UITextView content not appearing in UIAlerView - iphone

The content is about 230 lines. It does not appear in UITextView except when you click on it AND try to scroll down. Otherwise, it is a white blank view.
Any ideas why?
UITextView *termsOfService = [[UITextView alloc] initWithFrame:CGRectMake(20.0, 100.0, 245.0, 170.0)];
termsOfService.text = responseString;
termsOfService.font = [UIFont systemFontOfSize:13];
termsOfService.editable = NO;
termsOfService.delegate = self;
[alert addSubview:termsOfService];

Probably because UIAlertView isn't intended to have subviews added to it. Just because you can, doesn't mean you should.

Related

UIView in UIActionSheet

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.

Add some text to particular area in UITextView programmatically?

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];

UITextView, user scrolls uitextview but then it snaps back to original position, whats wrong?

I currently have a UITextView which is contained in a UIViewController using the following code:
UIViewController *container = [[UIViewController alloc] init];
container.view.frame = CGRectMake(0, 0,
[UIScreen mainScreen].bounds.size.width, 1000);
//[UIScreen mainScreen].bounds.size.height
container.view.userInteractionEnabled = YES;
container.view.clipsToBounds = YES;
UIImageView *imgView = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:#"myImage.png"]];
imgView.frame = container.view.frame;
imgView.userInteractionEnabled = YES;
[container.view addSubview:imgView];
[imgView release];
UITextView *textContained = [[UITextView alloc]
initWithFrame:CGRectMake(0, 0, container.view.bounds.size.width, 1000)];
//container.view.bounds.size.height
textContained.font = [UIFont fontWithName:#"Calibri" size:14];
textContained.scrollEnabled = YES;
textContained.editable = NO;
textContained.textColor = [UIColor whiteColor];
textContained.backgroundColor = [UIColor clearColor];
textContained.font = [UIFont boldSystemFontOfSize:14];
textContained.userInteractionEnabled = YES;
textContained.alwaysBounceVertical = YES;
textContained.contentSize = CGSizeMake(container.view.frame.size.width,
container.view.frame.size.height);
I then set my UItextView text property with some text, which extends past the current screen size. I then add my UITextView to my container using the following code.
switch (indexPath.row) {
case 0:
textContained.text = #"LOTS AND LOTS OF TEXT";
[container.view addSubview:textContained];
[self.navigationController pushViewController:container animated:YES];
[textContained release];
break;
default:
break;
}
[container release];
When I test this code, the text appears just fine in the UITextView and everything looks ok. But the problem is when I try to scroll down to see the remainder of the text. Everytime I scroll down the UITextView scrolls back in to its original position. I have tried several ways to get this to work, but I think I need some fresh eyes to see what I'm doing wrong.
Any help is greatly appreciated.
First, you don't want to set the contentSize of a UITextView, since it is determined by the length of text automatically.
Try to make the height of textView smaller. For example:
UITextView *textContained = [[UITextView alloc]
initWithFrame:CGRectMake(0, 0, container.view.bounds.size.width, 50)];
And give it more text, like:
textContained.text = #"LOTS AND LOTS OF TEXT\nLOTS AND LOTS OF TEXT\nLOTS AND LOTS OF TEXT\n\nLOTS AND LOTS OF TEXT\nLOTS AND LOTS OF TEXT\n";

UITextView not showing scroll bars

I have made UITextView programmatically but it is not showing the vertical and horizontal scroll bars. The code I have used is as follows,
UITextView *txtView = [[UITextView alloc] initWithFrame:CGRectMake(origin, imgFrame.size.height + 10, mScrollView.frame.size.width, 300)];
txtView.font = [UIFont fontWithName:#"HelveticaNeue" size:12];
txtView.textColor = [UIColor blackColor];
txtView.textAlignment = UITextAlignmentLeft;
txtView.editable = NO;
txtView.scrollEnabled = YES;
txtView.backgroundColor = [UIColor clearColor];
[txtView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
//[txtView flashScrollIndicators];
[txtView setText:[mDescArr objectAtIndex:index]];
[mScrollView addSubview:txtView];
[txtView release];
How can I make the scrollbars show?
I think there is no regular way to make them always visible (On Purpose!).
The BOOL txtView.showsVerticalScrollIndicator=TRUE/showsHorizontalScrollIndicator only shows the bar if the scrollView is active and hides it after some milliseconds inactivity.
If you comment [txtView flashScrollIndicators]; out then it only shows it once, to show the User that there is a possibility to scroll.
I think one (ugly) way to make it possible is, to call flashScrollIndicators more often, but this is no proper solution.
Do you have any text in it? It will only show the scroll bars if the text is bigger than the size of the view.
As bizarre as it may sound, do you ever collect and remove/edit subviews of your UITextView? When calling subviews from a UITextView (or UIScrollView), it will also return its scroll bars.

How to add a custom control to ActionSheet with default buttons?

I want to customise a UIActionSheet slightly; Just add a custom UIButton/UIImageView above the existing 2 buttons like in this previous post but with a custom button/image instead of text above the default buttons. I tried adding a simple UILabel to see if it works as in this post: UIActionSheet Customization.
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle: #""
delegate: self
cancelButtonTitle: NSLocalizedString(#"Cancel",#"cancel button")
destructiveButtonTitle: nil
otherButtonTitles: #"Send",nil];
actionSheet.tag = kCallActionSheetTag;
UILabel *btn = [[UILabel alloc] initWithFrame:
CGRectMake(18, 10, 140, 50)];
accountLabel.textAlignment = UITextAlignmentLeft;
accountLabel.textColor = [UIColor whiteColor];
accountLabel.text = #"Account";
accountLabel.font = [UIFont boldSystemFontOfSize:16];
accountLabel.backgroundColor = [UIColor clearColor];
[actionSheet addSubview:accountLabel];
[accountLabel release];
[actionSheet showInView:self.tabBarController.view];
[actionSheet setBounds:CGRectMake(0,0,320, 260)];
[actionSheet release];
If I use the code above, the two buttons are displaced vertically upwards and UILabel overlaps the top button. They seem to be locked to the top of the actionsheet. I would rather not add my own buttons and position them. What is the best way to do this?
Thanks
here is my suggestion,
My experience is from UIAlertView, I have not tested.
It is supposed to set top message huge to offset button y-offset.
then add your UILabel