I am confused regarding auto-complete bubble location while entering data in UITextView.
What i have observed is that depending upon its frame's origin , auto-complete bubble either comes on top or bottom. There is no fixed location, provided scrollEnabled is set to NO.
Here are the two links. Code is written in init()
http://www.flickr.com/photos/26021742#N00/6975525835/
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 150, 320, 41)] autorelease];
view.backgroundColor = [UIColor grayColor];
[self.view addSubview:view];
UITextView *growingTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 10, 200, 27)];
growingTextView.font = [UIFont fontWithName:#"Helvetica" size:13];
growingTextView.scrollEnabled = NO;
[view addSubview:growingTextView];
http://www.flickr.com/photos/26021742#N00/6975525727/
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 50, 320, 41)] autorelease];
view.backgroundColor = [UIColor grayColor];
[self.view addSubview:view];
UITextView *growingTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 10, 200, 27)];
growingTextView.font = [UIFont fontWithName:#"Helvetica" size:13];
growingTextView.scrollEnabled = NO;
[view addSubview:growingTextView];
Can anyone explain this observed behavior ???
I know that popovers and bubbles will always automatically adjust it's position for ease of use. It's already on Apple's code and in both images the bubble position makes sense.
Related
I have a title label in the navbar using the code below. I can't seem to get it to size to the width of the full view. Any idea how I might go about fixing this?
I thought self.view.bounds.size.width would size it to the full width of the view.
here's my navbar title label code and there's also a screenshot to visually show the problem.
thanks for the help
UILabel* tlabel=[[UILabel alloc] initWithFrame:CGRectMake(0,0, self.view.bounds.size.width, 48)];
tlabel.text=self.navigationItem.title;
tlabel.text = #"someText";
tlabel.font = [UIFont fontWithName:#"DIN-Bold" size:20];
tlabel.textColor=[UIColor whiteColor];
tlabel.backgroundColor = [UIColor colorWithRed:(219/255.0) green:(52/255.0) blue:(31/255.0) alpha:1] ;
tlabel.adjustsFontSizeToFitWidth=YES;
tlabel.textAlignment = UITextAlignmentCenter;
self.navigationItem.titleView=tlabel;
after code change from Paras Joshi it's correct on the right side but off on the left.
Use this bellow code in which I've added UILabel in UIView and then set that view as a titleView...
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 48)];
UILabel* tlabel=[[UILabel alloc] initWithFrame:CGRectMake(0,0, 320, 48)];
tlabel.text=self.navigationItem.title;
tlabel.text = #"someText";
tlabel.font = [UIFont fontWithName:#"DIN-Bold" size:20];
tlabel.textColor=[UIColor whiteColor];
tlabel.backgroundColor = [UIColor colorWithRed:(219/255.0) green:(52/255.0) blue:(31/255.0) alpha:1] ;
tlabel.textAlignment = UITextAlignmentCenter;
[headerView addSubview:tlabel];
self.navigationItem.titleView = headerView;
or add as a subview like below.
[self.navigationController.navigationBar addSubview:tlabel];
Try it with:
UILabel* tlabel=[[UILabel alloc] initWithFrame:CGRectMake(0,0, [UIScreen mainscreen].bounds.size.width, 48)];
May be it works.
you have imported uikit framework or not.import it to make it error free
I have UITextView in my iPhone app. In the UITextView i have added UIImageView as subview. When the entered text reaches the final height the texts are scrolling to top. Instead the UIImageView (with image) also scrolling top. How can i handle to stop the image scroll and allow the text to scroll? Here is my code for your reference,
messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(35, 5, 210, 30)];
messageTextView.delegate = self;
messageTextView.backgroundColor = [UIColor clearColor];
messageTextView.clipsToBounds = YES;
messageTextView.font = [UIFont fontWithName:#"Helvetica" size:14];
messageTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
textViewImageView = [[UIImageView alloc]initWithFrame: CGRectMake(0, 0, 210, 30)];
textViewImageView.image = [UIImage imageNamed: #"textbg.png"];
textViewImageView.contentMode = UIViewContentModeScaleToFill;
textViewImageView.contentStretch = CGRectMake(0.5, 0.5, 0, 0);
[messageTextView addSubview: textViewImageView];
[messageTextView sendSubviewToBack: textViewImageView];
[messageTextView addSubview:textViewLabel];
Can anyone please help me to solve this? Thanks in advance. Looking forward your reply.
have you considered to position the imageView behind the textView? Or is there any reason that forbids such a layout?
something like that:
UITextView *messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(35, 5, 210, 30)];
// ...
messageTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:messageTextView];
UIImageView *textViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(35, 5, 210, 30)];
// ...
textViewImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:textViewImageView];
[self.view sendSubviewToBack:textViewImageView];
Maybe this could help.
Use the scrollview delegate to reposition your image when it reaches the bounds.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
CGRect imageFrame = textViewImageView.frame;
imageFrame.origin.y = scrollView.contentOffset.y - (scrollView.contentSize.height - scrollView.frame.size.height);
textViewImageView.frame = imageFrame;
}
}
This should work:
[yourTxtView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"your image.png"]]];
I am trying to add a UILabel programmatically into my UIToolBar but it dose not seem to be appearing. This is what I am doing with my code.
- (void) viewWillAppear:(BOOL)animated
{
// Create custom toolbar at top of screen under navigation controller
[matchingSeriesInfoToolBar setFrame:CGRectMake(0, 60, 320, 30)];
matchingSeriesInfoToolBar = [UIToolbar new];
[matchingSeriesInfoToolBar sizeToFit];
CGFloat toolbarHeight = 30;
CGRect mainViewBounds = [[UIScreen mainScreen] applicationFrame];
[matchingSeriesInfoToolBar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds), 0, CGRectGetWidth(mainViewBounds), toolbarHeight)];
matchingSeriesInfoToolBar.tintColor = [UIColor darkGrayColor];
[self.view addSubview:matchingSeriesInfoToolBar];
// Create size of uitableview (to fit toolbar.
[matchingSeriesTableView setFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height - 30)];
[self.view addSubview:matchingSeriesTableView];
// Ad UILabel to the toolbar
UIBarButtonItem *textFieldItem = [[UIBarButtonItem alloc] initWithCustomView:manufSelectionLabel];
matchingSeriesInfoToolBar.items = [NSArray arrayWithObject:textFieldItem];
manufSelectionLabel.text = #"Hello World!";
[super viewWillAppear:animated];
}
So pretty much I have created a custom toolbar which I have changed the usual location from the bottom of the screen, to appear under the UINavigationController, this is also added to the view like this so it animated properly in the view transitions..
After which I create the size of the tableview so that it appears after the custom toolbar..
then from there I am trying to add a UILabel to the toolbar.. but for some reason its not working out.
Any help would be greatly appreciated.
You must actually create the label somewhere. This code works just fine.
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[self.view addSubview:toolbar];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
label.backgroundColor = [UIColor clearColor];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:label];
toolbar.items = [NSArray arrayWithObject:item];
label.text = #"Hello World";
In the code you posted you don't ever make a UILabel. Your comment says Ad UILabel to the toolbar but you then proceed to make a UIBarButtonItem with a custom view manufSectionLabel.
Where is the code which creates manufSectionLabel?
PS This line does nothing :
[matchingSeriesInfoToolBar setFrame:CGRectMake(0, 60, 320, 30)];
because at that point matchingSeriesInfoToolbar is nil - you haven't made it yet!
I am currently creating my own custom section headers but I have never dont any text editing via code.. and my new method that I am using to populate my custom header is doing some weird things as shown below
I would like to change the text to white and be slightly bolder and also make the white background transparent..
this is the code I am using to do this
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
[headerView setBackgroundColor:[UIColor grayColor]];
// Add the label
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.5, 20, 20)];
// do whatever headerLabel configuration you want here
headerLabel.text = [self tableView:tableView titleForHeaderInSection:section];
[headerView addSubview:headerLabel];
// Return the headerView
return headerView;
}
I have tried this
[headerLabel.backgroundColor:[UIColor clearColor]];
etc but its not working :(
I would like to change the text to white...
UILabel's textColor property is your friend here.
And slightly bolder...
No problem! headerLabel.font = [UIFont boldSystemFontOfSize:mySize];
And make a white transparent background.
Whoa, whoa, that is the worst setter syntax ive ever seen!!! My lord, myLabel.backgroundColor is a getter, change:
[headerLabel.backgroundColor:[UIColor clearColor]];
to:
[headerLabel setBackgroundColor:[UIColor clearColor]];
Lucky for you, using your syntax would have just sent a message to nil, which is defaulting the background color of your label to white.
Use following code...
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UILabel *headername = [[UILabel alloc]initWithFrame:CGRectMake(20, 5, 270, 34)];
headername.backgroundColor = [UIColor clearColor];
headername.textColor = [UIColor blackColor];
if(section == 0)
{
headername.text = #"Name that u wish";
}
else
{
headername.text = #"Name that u wish";
}
UIView *headerView = [[UIView alloc] init];
UIImageView *tempimage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 5, 300,34)];
tempimage.image = [UIImage imageNamed:#"whitebackground.png"];
[headerView addSubview:tempimage];
[headerView addSubview:headername];
return headerView;
}
Hope, this will help you...chill
all i have done to get the customized header in table is as following and it is working fine for me
UIView *containerView =
[[[UIView alloc]
initWithFrame:CGRectMake(0, 0, 300, 60)]
autorelease];
UILabel *headerLabel =
[[[UILabel alloc]
initWithFrame:CGRectMake(10, 20, 300, 40)]
autorelease];
headerLabel.text = NSLocalizedString(#"Header for the table", #"");
headerLabel.textColor = [UIColor whiteColor];
headerLabel.shadowColor = [UIColor blackColor];
headerLabel.shadowOffset = CGSizeMake(0, 1);
headerLabel.font = [UIFont boldSystemFontOfSize:22];
headerLabel.backgroundColor = [UIColor clearColor];
[containerView addSubview:headerLabel];
self.tableView.tableHeaderView = containerView;
i just put it in viewDidLoad: method
Im trying to make my own calendar similar to iCal and all is going well except for one thing. I plan to have the calendar selection up the top then a table list down the bottom. I can do this but then the calendar is in the same subview as the table and scrolls with it. Although I am currently not using a nib if I build it in a nib then the table wont resize to take up whatever the calendar doesn't. ie it should be larger in say February where as December will be small (exactly like the apple iCal version) I have seen other apps do this. Any ideas on how I would go about this?
Add the tableview and the calendar view separately to the main view.
Example:
- (void)loadView {
[super loadView];
UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
topView.backgroundColor = [UIColor darkGrayColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 280, 60)];
label.text = #"Stationary top view";
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
[topView addSubview:label];
[label release];
[self.view addSubview:topView];
[topView release];
UITableView *tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, 320, 380) style:UITableViewStyleGrouped];
tableview.delegate = self;
tableview.dataSource = self;
[self.view addSubview:tableview];
[tableview release];
}
Screenshot:
alt text http://static.benford.name/tableview_with_topview.png