UITextView not showing scroll bars - iphone

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.

Related

How to stick the cursor position on the left corner in UITextView?

I know this could be funable question , but still i'm getting problem in that as i'm new to iphone.
Problem -> Actually i'm creating custom textview in the cell and taking view up and down when keyboard appears. So problem i'm getting is when textViewShouldBeginEditing calls and my view up's the cursor of the textview also up and hides the cursor, i'm unable to see the text which i wrote in the textview.
i am writing this code in the UITableView:
UITextView *_RepliesPost = [[UITextView alloc] initWithFrame:CGRectMake(5, 2, 260, 32)];
_RepliesPost.textAlignment = UITextAlignmentLeft;
_RepliesPost.font = [UIFont fontWithName:#"Helvetica neue" size:6.00];
_RepliesPost.font = [UIFont boldSystemFontOfSize:10];
_RepliesPost.tag=15;
_RepliesPost.delegate=self;
_RepliesPost.backgroundColor = [UIColor whiteColor];
_RepliesPost.textColor = [UIColor blackColor];
[cell.contentView addSubview:_RepliesPost];
So please help me to solve this problem ,,, thanks in advance.
Try adding the UITextView as an accessory view, rather than as a content view. Something like this:
[cell setAccessoryView:_RepliesPost];
This remains visible when editing. I also prefer to set my UITextView Alignment to UITextAlignmentRight when doing this, as it looks the most aesthetically pleasing.

How can I add a UIView above viewable area of a UITableView?

I understand that there is a tableHeaderView property, but when ever I add my view to that, it is not hidden above the scroll area.
What I would like to have is, my custom view shown when you pull down the tableview and hold and you see my UIView brought into view. This is done on many apps to put a logo or such slightly hidden until a user pulls down on the tableview (Twitter/Facebook when you pulldown).
I am currently using the following and it is not putting it out of the view:
UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 20)];
l.text = #"Hidden Text";
l.textColor = [UIColor redColor];
self.tableView.tableHeaderView = l;
[l release];
Since UITableView is actually a UIScrollView with some extra functionality, you can use contentInset to obtain the effect you want. The trick is to use a negative value for the top inset. This will normally hide your header view, but it will still be viewable when the table bounces.
So, after you add the label to the header view, just set the contentInset like this:
UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 20)];
l.text = #"Hidden Text";
l.textColor = [UIColor redColor];
self.tableView.tableHeaderView = l;
//add this
[self.tableView setContentInset:UIEdgeInsetsMake(-l.bounds.size.height, 0.0f, 0.0f, 0.0f)];
[l release];
The best solution here is to add your view to the header, as you had mentioned you tried, and then in your controller's viewDidLoad actually scroll the tableview downward programmatically until the header view you wanted hidden is hidden. This can be done a number of different ways. The easiest is probably:
[self.tableView setContentOffset: CGPointMake(0, myHeaderHeight)];
Simply have a 0-height header view, and then have a subview of that be positioned with a negative y, and so that the bottom edge of the subview is the top of the view.
UIWindow* window = [[UIApplication sharedApplication].delegate.window;
[window addSubview: your-overlayview];

Can anyone show me an example on how to add text to a UIScrollView?

Most of the code examples I have seen show images that are added. I am looking for an example that essentially just shows about 10-15 row of data being added to a UIScrollVIew.
Any solid advice would be highly appreciated.
Put this into: viewDidLoad{}
//create UITextView
UITextView *myUITextView = [[UITextView alloc] initWithFrame:CGRectMake(20,188,280,260)];
myUITextView.text = infoText;
myUITextView.textColor = [UIColor lightGrayColor];
myUITextView.font = [UIFont systemFontOfSize:14];
[myUITextView setBackgroundColor:[UIColor clearColor]];
myUITextView.editable = NO;
myUITextView.scrollEnabled = YES;
[Scrollerview addSubview:myUITextView];
[myUITextView release];
where 'infoText' is your text, and 'Scrollerview' is your uiScrollView
Check out UITextView, its fairly easy to implement, but it might not have the versatility that you want.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextView_Class/Reference/UITextView.html

ios uitextfield like notes

I wish that my uitextfield seems like the notes of the iPhone, yellow with the lines..
what's the best way to do this?
thanks in advance!
You mean UItextview right? ... its not a UITextField.
However, clear your background on the UITextView.
self.textView.backgroundColor = [UIColor clearColor];
Then create ImageView that u put as a subview to your textview.
backgroundimage = [[UIImageView alloc] initWithFrame: CGRectMake(0, -14,textView.frame.size.width, textView.fram.size.height)];
set a pattern image as backgroundColor. This will be your lines. Just create on or two lines . Then it should repeat itself.
backgroundimage.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"lines.png"];
then add your subview to the textview.
[self.textView addSubview:backgroundimage];
Good luck!

UITextView content not appearing in UIAlerView

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.