I create an instance of UITextView programmatically. I want to add some text to particular area in UITextView programmatically. Here is my code to create UITextView.
UITextView *textView =[[UITextView alloc]init];
textView.frame=CGRectMake(0,0,282,210);
[textView setReturnKeyType:UIReturnKeyDone];
[self.view addSubview:textView];
For example I want to add some text to particular Area CGRectMake(260,190,20,20).
Then add this text to UITextView.
Programmatically, please any one guide me, how is it possible to do this?
You could add an UILabel there.
UITextView *textView = [[UITextView alloc] init];
TextView.frame = CGRectMake(0.0,0.0,282.0,210.0);
[textView setReturnKeyType: UIReturnKeyDone];
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(260.0,190.0,20.0,20.0);
label.text = #"T"; //here you set the text you want...
[textView.view addSubview: label];
[self.view addSubview: textView];
Related
I m adding a UIView in UIActionSheet and I need to add four labels on the view and a close button.But I need the UIactionSheet to start from center of screen.When I m adhusting the dimensions I couldnot get it .
-(IBAction)buttontapped:(id)sender{
UIView *showDetailsView = [[UIView alloc]initWithFrame:CGRectMake(0,10, 320, 260)];
showDetailsView.backgroundColor = [UIColor whiteColor];
UILabel *name =[[UILabel alloc] init];
[name setFrame:CGRectMake(10, 40,250, 50)];
name.textAlignment = UITextAlignmentLeft;
name.backgroundColor = [UIColor clearColor];
name .font=[UIFont fontWithName:#"arial" size:12];
name.text=#"Name";
[showDetailsView addSubview:name];
UIActionSheet *aac = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:#"Close", nil];
aac.actionSheetStyle = UIActionSheetStyleAutomatic;
[aac addSubview:showDetailsView];
[aac setFrame:CGRectMake(0,0,320,400)];
[aac showInView:self.view];
}
I can see it added from the bottom but it is not expanding to the center of screen like in the following figure:I need to increase its height.
From one of the SO's answer I get this method and it's works like charm :)
-(void)setActionSheetHeight
{
CGRect actionSheetRect = self.myActionSheet.frame;
CGFloat orgHeight = actionSheetRect.size.height;
actionSheetRect.origin.y -= 214; //height of picker
actionSheetRect.size.height = orgHeight+214;
self.myActionSheet.frame = actionSheetRect;
[self.myPicker setShowsSelectionIndicator:YES];
CGRect pickerRect = self.myPicker.frame;
pickerRect.origin.y = orgHeight;
self.myPicker.frame = pickerRect;
}
Here myActionSheet is one UIActionSheet iVar.
Here myPicker is one UIPickerView iVar.
Instead of 214 static value you can set your desired value and according to that it will set the height of the UIActionSheet.
NOTE
Must be called after the action sheet is shown ie after the [self.myActionSheet showFromTabBar:self.tabBarController.tabBar]; kind of line of code. Means after call the show method on action sheet.
Use this:
[aac setBounds:CGRectMake(0,0,320,400)];
UIActionSheet is designed to be presented from the bottom of the screen.
You can display it in center on ipad only..not in iphone.
You can use custom Alertview for your requirement.
https://github.com/alokard/BlockAlertView
When you present the actionsheet, you need to send appropriate message to present it. Refer to
showFromRect:inView:animated:
showInView:
For showInView:, you can have an invisible view with the bottom at mid-height of the view controller and top aligned to the top of viewcontroller.
For showFromRect:inView:animated:, if you have any UIView to which the actionsheet needs to be anchored, you can used it there.
I want create some view, and add dynamically to it text and images
Somebody knows how I can to do it?
Thanks
Broad question, but this should get you on the right path: (Pop this into a viewcontroller)
-(void)addStuffToView{
UIView* myView = [self view]; // get the view controller's view
UIImageView* myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,100,100)];
[myImageView setImage:[UIImage imageNamed:#"imagefile.jpg"]];
[myView addSubview:myImageView];
[myImageView release];
UILabel* myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,100,100,50)];
myLabel.text = #"Some text here";
[myView addSubview:myLabel];
[myLabel release];
}
Then, bind this method to your UIButton's touchUpInside event using Interface Builder.
I successfully display UILabel inside a UIScrollView,
but how to skip/jump/go to end of the text dynamicaly ?
My code is as following and work perfect.
Which code I have to add to jump to the end of the text ?
is it possible ?
I try to reproduce an effect of log/trace...
Thanks
Fred
-(void) log:(NSString *)msg
{
// alocate and initialize scroll
UIScrollView *myScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 20.0f, 320.0f, 460.0f)];
// alocate and initialize label
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 20.0f, 320.0f, 460.0f)];
myLabel.text = msg; //a long text
// set line break mode to word wrap
myLabel.lineBreakMode = UILineBreakModeWordWrap;
// set number of lines to zero
myLabel.numberOfLines = 0;
// resize label
[myLabel sizeToFit];
// set scroll view size
myScroll.contentSize = CGSizeMake(myScroll.contentSize.width, myLabel.frame.size.height);
// add myLabel
[myScroll addSubview:myLabel];
// add scroll view to main view
[self.view addSubview:myScroll];
// release label and scroll view
[myLabel release];
[myScroll release];
}
You can go with setting contentOffset for the UIScrollView
Check this : setContentOffset:animated
Hope this is what you want.
You can use setContentOffset method of UIScrollView to scroll, like :
[scrollView setContentOffset:CGPointMake(x, y) animated:YES];
I have a need to display text that includes HTML tags etc and TTStyledTextLabel fits the bill.....but it does not scroll.
I placed one inside a UITextView but this refuses to scroll? If I enter the text directly in the UITextView it scrolls OK but then I see all the HTML unformatted.
Is there a way to set TTStyledTextLabel to scroll?
Thanks
Try putting the TTStyledTextLabel in a UIScrollView.
Alternately, you can consider using a UIWebView directly.
I finally got a suitable work around...
CGSize constraintSize;
CGSize stringSize;
// make an overly big size allowance
constraintSize.width = 300;
constraintSize.height = 2000;
NSString *s = #"this can be text as long or as short as required...;
UIFont *f = [UIFont fontWithName:#"Arial" size:14];
stringSize =[s sizeWithFont:f constrainedToSize: constraintSize lineBreakMode: UILineBreakModeWordWrap];
// create a label to accomodate the text
UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(14, 2, stringSize.width, stringSize.height)];
l.text = s;
[l setNumberOfLines:0];
[l sizeToFit];
// now create a TTStyledTextLabel to match the size we just obtained above
TTStyledTextLabel *tl = [[TTStyledTextLabel alloc] initWithFrame:[l frame]];
// set the text making use of links etc
tl.text = [TTStyledText textFromXHTML:l.text lineBreaks:YES URLs:YES];
[tl setBackgroundColor:[UIColor clearColor]];
tl.textColor = [UIColor whiteColor];
UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 185, 320, 300)];
// adjust scrollview content size to accomodate the TTStyledTextLabel
[sv setContentSize:CGSizeMake(tl.frame.size.width, tl.frame.size.height)];
[sv addSubview:tl];
[self.view addSubview:sv];
Now I can have an auto sizing TTStyledTextLabel that scrolls ;-)
I have a the following piece of code:
-(IBAction)routePicker
{
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 264, 320, 216)];
UIPickerView *thePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,0,320,216)];
thePickerView.dataSource = self;
thePickerView.delegate = self;
[myView addSubview:thePickerView];
[self.view addSubview:myView];
}
this creates a subview of the UIPickerView, which contains predefined items I added.
At the moment this IBAction is linked to a custom button, so when I click on the button it loads the subview. I want to text box instead of a custom button. So when I click/tap on the text box my UIPickerView should load in the subview.
Regards,
Stephen
Check out this example from apple
Date Cell picker