Search Results

Search found 34 results on 2 pages for 'sizetofit'.

Page 1/2 | 1 2  | Next Page >

  • sizeToFit label voids align right / set minimum width of label

    - by Deco
    Here is my code I am using to make a label (which contains content of an unknown length) the correct height for the content. (lines is equal to 0) myLabel.text =[NSString stringWithFormat:@"%@", myLabelContent]; myLabel.frame = CGRectMake(myLabel.frame.origin.x, myLabel.frame.origin.y, myLabel.frame.size.width, 800); [myLabel sizeToFit]; The only problem is, it is resizing the width as well as the height. I have two labels side by side, one aligned left, one aligned right. The left aligned one works fine. However, the right aligned one becomes intended (from the right). Because of its width resize, the content always starts at the origin.x position (in effect) because the label is made to be the shortest width required. I hope that makes sense. Is there a way to override or reset the width after auto resize had solved the height problem, or set a minimum width for the label? Many Thanks in advance, Deco

    Read the article

  • Monotouch auto resizing views in iphone

    - by Tim Bassett
    I have created a view in interface builder that contains another view (content area) and a button bar at the bottom. The hierarchy is as: ->View --->mapContainer UIView ----->map MKMapView ----->OverlayView UIView --->ToolBar UIToolBar I would like the mapContainer to resize to full window when the ToolBar is hidden. I would like the map and the OverlayView to resize to the mapContainer size I have attempted the following code, but it has no effect. Please advise? public override void ViewDidLoad () { base.ViewDidLoad (); this.mapContainer.AutosizesSubviews = true ; this.View.AutosizesSubviews = true ; try { this.mapContainer.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth ; this.map.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth ; this.map.SizeToFit(); this.mapContainer.SizeToFit(); this.map.SizeToFit(); this.View.Frame = new System.Drawing.RectangleF(0,0,this.View.Frame.Width, this.View.Frame.Height ); this.mapContainer.LayoutSubviews(); } catch(Exception ex) { Console.Write(ex.ToString()); } }

    Read the article

  • Vertically align UILabel

    - by Ashish Agarwal
    I am trying to vertically align the text in the UILabel view of my app. The problem is that I want the text to be vertically aligned to the top and the size of the label to be 280 x 150. I am only able to achieve one of these 2 things. If I remove the line [myLabel sizeToFit]; then the alignment of the text is alright but the size is messed up. But if I add the above line, then the alignment is messed up but the size is alright. How do I fix this problem. I've added the code below - CGRect labelFrame = CGRectMake(22, 50, 280, 150); UILabel *myLabel = [[UILabel alloc] initWithFrame:labelFrame]; [myLabel setText:finalRecipe]; [myLabel setBackgroundColor: [UIColor lightGrayColor]]; [myLabel setNumberOfLines:0]; [myLabel sizeToFit]; [self.view addSubview:myLabel];

    Read the article

  • how do i let text fit to UIButton?

    - by iAsk
    problem: Button size is enough, however when I change title, the title text cannot fit the button width. Any SDK function can solve this problem, or I need to manually code to solve it? Please refer to following pictures. design in the nib file. initial show in simulator when I change the title text tried some ways before _button.titleLabel.adjustsFontSizeToFitWidth = YES; the way will change my font size. I cannot accept the way. [_button setTitleEdgeInsets:UIEdgeInsetsMake(10.0, 10.0, 0.0,0.0)]; the way change label's position only, not label size. [_button.titleLabel sizeToFit]; result is same with picture(3). [_button sizeToFit]; title moved to upper left corner, and the title still the same result. Just confused, my button size is big enough, why title size is so small?

    Read the article

  • How do I resize table view after resizing it's footer?

    - by Pedro
    I have a UITableView with header & footer added with code following the pattern shown in Apple's recipes example so the code for the footer is... if (tableFooterView == nil) { [[NSBundle mainBundle] loadNibNamed:@"DetailFooterView" owner:self options:nil]; self.tableView.tableFooterView = tableFooterView; } The footer NIB contains nothing more than a UITextView & I set text & resize with... CGSize size = [footerText sizeWithFont:[footerTextView font] constrainedToSize:CGSizeMake(304.0, 500.0)]; CGRect frame = CGRectMake(8.0, 0.0, size.width, size.height + 24.0); footerTextView.frame = frame; footerTextView.text = footerText; [tableFooterView sizeToFit]; That all works however I can't get the UITableView to resize around the resized footer. If I set the original size of the footer for any possible text I have a big whitespace in most cases. If I set it smaller then I can push the view up to see the whole text but it bounces back on release. I've tried [[self view] sizeToFit]; but that doesn't work. Can anyone fill me in? Cheers & TIA, Pedro :)

    Read the article

  • MPVolumeView, avoid displaying "No Volume Available"

    - by Emil
    Hey. I have a project with a MPVolumeView in it. It is set up, and it works, the only thing is that when I mute the device, the text "No Volume Available" comes up instead of the MPVolumeView. The volumeView is initialized in the view volumeBounds, with that view's bounds. MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:volumeBounds.bounds] autorelease]; [volumeBounds addSubview:volumeView]; [volumeView sizeToFit]; Thanks :)

    Read the article

  • MPVolumeView, avoid displaying "No Volume Available"

    - by Emil
    Hey. I have a project with a MPVolumeView in it. It is set up, and it works, the only thing is that when I mute the device, the text "No Volume Available" comes up instead of the MPVolumeView. The volumeView is initialized in the view volumeBounds, with that view's bounds. MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:volumeBounds.bounds] autorelease]; [volumeBounds addSubview:volumeView]; [volumeView sizeToFit]; Thanks :)

    Read the article

  • Cannot get UISearchBar Scope Bar to appear in Toolbar on iPad

    - by Jann
    This is really causing me fits. I put a toolbar on the IUView on the iPad. I added the following: Search Bar (not Search Bar and Search Display) to the toolbar. I set the options to be as follows: Show Cancel Button, Show Scope Bar, Scope Button Titles are: "Title1" and "Title2" (with Title2's radio button selected). Opaque, Clear Context and Auto Resize are checked. I hooked up the delegate of Search Bar to the "File's Owner" and linked it to IBOutlet theSearchBar. In my viewWillAppear I have the following: [theSearchBar setScopeButtonTitles:[NSArray arrayWithObjects:@"Near Me",@"Everywhere",nil]]; //Just in case: [theSearchBar setShowsScopeBar:YES]; //doesn't seem to do anything: //[theSearchBar sizeToFit]; searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:theSearchBar contentsController:self]; [self setSearchDisplayController:searchDisplayController]; [searchDisplayController setDelegate:self]; [searchDisplayController setSearchResultsDataSource:self]; //again--does not seem to do anything..but people have suggested it: [theSearchBar sizeToFit]; Okay, so far, I thought, so good. So, I made the File's Owner .m file to be a delegate for: UISearchBarDelegate, UISearchDisplayDelegate. My issue: I have yet to implement the delegates necessary to do the search but still... shouldn't I be seeing the scopeBar next to the search field when I click into the search field? Just so you know I DO see the log of the characters I type, so the delegate is working. I have the following dummy functions in the .m file (just in case) // called when keyboard search button pressed - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { NSLog(@"Search Button Clicked\n"); [theSearchBar resignFirstResponder]; } // called when cancel button pressed - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { NSLog(@"Cancel Button Clicked\n"); [theSearchBar resignFirstResponder]; } - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { NSLog(@"Search Text So Far: '%@'\n",searchText); } - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { return YES; } - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar { return YES; } Why doesn't the Scope Bar appear? A results UIPopoverController appears with the title "Results" and "No results found" (of course) when i type the first character in my search...but no scope bar. (not that i expect anything other than "No Results Found". I am wondering where the scope bar is supposed to appear...in the titleView of the UIPopover? In the toolbar to the right of the search area? Where?

    Read the article

  • Can I change the size of UIActivityIndicator?

    - by wolverine
    Whatever size i give to it while allocation, it shows fixed size only. Is it possible to increase it? Code: activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame: CGRectMake(142.00, 212.00, 80.0, 80.0)]; [[self view] addSubview:activityIndicator]; [activityIndicator sizeToFit]; activityIndicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin); activityIndicator.hidesWhenStopped = YES; activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

    Read the article

  • resizing UITableView to fit content

    - by MiMo81
    I am creating an app which will have a question in a UILabel and a multiple choice answers displayed in UITableView, each row showing a multiple choice. Questions and answers will vary, so I need this UITableView to be dynamic in height. I would like to find a "sizeToFit" work around for the table. Where the table's frame is set to the height of all it's content. Can anyone advise on how I can achieve this? Thank you.

    Read the article

  • Cannot get UISearchBar Scope Bar to appear in Toolbar (or anywhere) on iPad

    - by Jann
    This is really causing me fits. I see a lot of info on putting a UISearchBar in the top row of a UITableView -- but I am putting the UISearchBar into the Toolbar at the top of my screen (on the iPad). I cannot find ANYTHING regarding how to handle UISearchBar and UISearchDisplayController using a UIPopoverController on the iPad. Any more info about the UISearchDisplayController using a UIPopoverController would be greatly appreciated. Please help with this as I am at my wit's end. Using IB, I put a toolbar on the IUView on the iPad. I added the following: Search Bar (not Search Bar and Search Display) to the toolbar. I set the options to be as follows: Show Cancel Button, Show Scope Bar, Scope Button Titles are: "Title1" and "Title2" (with Title2's radio button selected). Opaque, Clear Context and Auto Resize are checked. I hooked up the delegate of Search Bar to the "File's Owner" and linked it to IBOutlet theSearchBar. In my viewWillAppear I have the following: //Just in case: [theSearchBar setScopeButtonTitles:[NSArray arrayWithObjects:@"Near Me",@"Everywhere",nil]]; //Just in case (again): [theSearchBar setShowsScopeBar:YES]; //doesn't seem to do anything: //[theSearchBar sizeToFit]; searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:theSearchBar contentsController:self]; [self setSearchDisplayController:searchDisplayController]; [searchDisplayController setDelegate:self]; [searchDisplayController setSearchResultsDataSource:self]; //again--does not seem to do anything..but people have suggested it: [theSearchBar sizeToFit]; Okay, so far, I thought, so good. So, I made the File's Owner .m file to be a delegate for: UISearchBarDelegate, UISearchDisplayDelegate. My issue: I have yet to implement the delegates necessary to do the search but still... shouldn't I be seeing the scopeBar next to the search field when I click into the search field? Just so you know I DO see the log of the characters I type, so the delegate is working. I have the following dummy functions in the .m file (just in case) // called when keyboard search button pressed - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { NSLog(@"Search Button Clicked\n"); [theSearchBar resignFirstResponder]; } // called when cancel button pressed - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { NSLog(@"Cancel Button Clicked\n"); [theSearchBar resignFirstResponder]; } - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { NSLog(@"Search Text So Far: '%@'\n",searchText); } - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { return YES; } - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar { return YES; } Why doesn't the Scope Bar appear? A results UIPopoverController appears with the title "Results" and "No results found" (of course) when i type the first character in my search...but no scope bar. (not that i expect anything other than "No Results Found". I am wondering where the scope bar is supposed to appear...in the titleView of the UIPopover? In the toolbar to the right of the search area? Where?

    Read the article

  • Setting navigationItem.leftBarButtonItem - why does it hide my back arrow button ?

    - by gotye
    Hey guys, When I do this : // --------------- SETTING NAVIGATION BAR LEFT BUTTON activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0,0.0,25.0,25.0)]; [activityIndicator sizeToFit]; activityIndicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin); UIBarButtonItem *loadingView = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator]; //loadingView.target = self; self.navigationItem.leftBarButtonItem = loadingView; [activityIndicator startAnimating]; // --------------- It hides my back arrow button (the one I use to get back to the previous controller) ... why is that ?!? How am I supposed to add my activityIndicator next to my back arrow ? (i already used titleView and rightbarbuttonitem) Thanks a lot, Gotye.

    Read the article

  • setSearchDisplayController considered private-API?

    - by Adun
    Hi, I recently submitted an app for app review but I got rejected because of the use of a private API. I'm still a bit new to iPhone developing so I was wondering if someone could help me understand how this part was rejected: UISearchBar *searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 0)] autorelease]; searchBar.showsCancelButton = NO; searchBar.placeholder = @"Search Exhibitors"; [searchBar sizeToFit]; [self.tableView setTableHeaderView:searchBar]; UISearchDisplayController *searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]; [self performSelector:@selector(setSearchDisplayController:) withObject:searchDisplayController]; [searchDisplayController setDelegate:self]; [searchDisplayController setSearchResultsDataSource:self]; [searchDisplayController setSearchResultsDelegate:self]; [searchDisplayController release]; The part that they mentioned was the "setSearchDisplayController". I based the searching of a UITableView on the example given here. So can anyone explain why this is considered a private API?

    Read the article

  • Is it possible to change the border color of a UISearchDisplayController's search bar?

    - by prendio2
    I have a UISearchBar added as my table header with the following code. searchBar = [[UISearchBar alloc] initWithFrame:self.tableView.bounds]; searchBar.tintColor = [UIColor colorWithWhite:185.0/255 alpha:1.0]; [searchBar sizeToFit]; self.tableView.tableHeaderView = searchBar; Then I set my UISearchDisplayController up as follows. searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]; [searchDisplayController setDelegate:self]; [searchDisplayController setSearchResultsDataSource:self]; Everything functions as I would like except that the UISearchDisplayController has added a blue(ish) border above the search bar — this bar does not recognise the tintColor I have set on the search bar. Is it possible to change the color of this bar? It is obviously not absolutely crucial but that line is going to bug me forever if it stays blue like that!

    Read the article

  • Calculate NSString size to adjust UITextField frame

    - by Bernd Plontsch
    I have issues calculating the accurate size of a NSString displayed in a UITextField. My goal is to update the textfield frame size according to the string size programmatically (without using sizeToFit). I am using the sizeWithFont function. -(void)resizeTextFieldAccordingToText:(NSString*)textFieldString { CGPoint originalCenter = self.textField.center; UIFont* currentFont = [textField font]; CGSize newSize = [textFieldString sizeWithFont:currentFont]; //Same incorrect results with the extended version of sizeWithFont, e.g. //[textFieldString sizeWithFont:currentFont constrainedToSize:CGSizeMake(300.0, 100.0) lineBreakMode:NSLineBreakByClipping]; [self.textField setFrame:(CGRectMake(self.textField.frame.origin.x, self.textField.frame.origin.y, newSize.width, newSize.height))]; [self.textField setCenter:originalCenter]; } Problem: While this return correct size results at first its becomes more and more unprecise by adding characters therefore finally starts clipping the string (as seen in the right screenshot). How do I get the accurate size of the textField string for correctly adjusting its size?

    Read the article

  • MPVolumeView is not visible on the view

    - by Faiz
    Hi everybody, I am using MPVolumeView in an application to control the volume of a audio track. I have used following code. but volume view is not visible on the view. Anybody has faced the same problem?? MPVolumeView *myVolume = [[MPVolumeView alloc] initWithFrame:CGRectMake(10, 10, 300, 40)]; [myVolume sizeToFit]; [self.view addSubview:myVolume]; [myVolume release]; any solution?? Thanx in advance.

    Read the article

  • iphone - Search bar disappears from my root view controller

    - by Sudharsanan
    Hi, I have a search bar in my main screen - root table view controller. If I browse other screens and come back, sometimes, the search bar disappears. Here's my code. searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 0)]; searchBar.delegate = self; searchBar.tintColor = [UIColor blackColor]; [searchBar sizeToFit]; self.tableView.tableHeaderView = searchBar; searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]; searchDisplayController.delegate = self; searchDisplayController.searchResultsDataSource = self; searchDisplayController.searchResultsDelegate = self; Is there anything wrong with my code or is it one of the quirks of SDK 3.0?

    Read the article

  • Placing text on UIView in custom location

    - by JAM
    I am trying to calculate a position to place label on the screen. The goal is to place "word" label in lower right corner of the first square block If yellowish square is defined as myView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 70, 70)]; [self.view addSubview:myView]; [myView setBackgroundColor:[UIColor colorWithHexString:@"FFFFEC"]]; Using it, i'd like to place a label in it's lower right corner l1 = [[UILabel alloc] init]; [l1 setText:@"word"]; [l1 setFrame:CGRectMake(myView.frame.origin.x + myView.frame.size.width, myView.frame.origin.y + myView.frame.size.height, 700, 700)]; [l1 setFont:[UIFont fontWithName:@"Arial" size:10.0]]; [l1 setBackgroundColor:[UIColor colorWithHexString:@"CCFFFEC"]]; [l1 setTextAlignment:UITextAlignmentRight]; [l1 sizeToFit]; This is what happens: The matter here obviously, is in a correct offset. Knowing the font and size of text, how can one correctly calculate it?

    Read the article

  • How to add a multiline title bar in UINavigationController

    - by Cocoa Matters
    I have try to add a two line title bar in UINavigationController I want to adjust font size automatically set according to string length.My String max size goes to 60. I have try to implemented through following code UILabel *bigLabel = [[UILabel alloc] init]; bigLabel.text = @"1234567890 1234567890 1234567890 1234567890 1234567890 123456"; bigLabel.backgroundColor = [UIColor clearColor]; bigLabel.textColor = [UIColor whiteColor]; bigLabel.font = [UIFont boldSystemFontOfSize:20]; bigLabel.adjustsFontSizeToFitWidth = YES; bigLabel.clipsToBounds = NO; bigLabel.numberOfLines = 2; bigLabel.textAlignment = ([self.title length] < 10 ? NSTextAlignmentCenter : NSTextAlignmentLeft); [bigLabel sizeToFit]; self.navigationItem.titleView = bigLabel; It didn't work for me can you help me please. I have to made this for iPhone and iPad screen

    Read the article

  • Subclassing UINavigationBar ... how do I use it in UINavigationController?

    - by funkadelic
    Hi, I wanted to subclass UINavigationBar (to set a custom background image & text color) and use that for all the navigation bars in my app. Looking at the API docs for UINavigationController, it looks like navigationBar is read-only: @property(nonatomic, readonly) UINavigationBar *navigationBar Is there a way to actually use a custom UINavigationBar in my UIViewControllers? I know that other apps have done custom navigation bars, like flickr: Here is my UINavigationBar subclass: #import <UIKit/UIKit.h> @interface MyNavigationBar : UINavigationBar <UINavigationBarDelegate> { } @end the implementation #import "MyNavigationBar.h" @implementation MyNavigationBar - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { // Initialization code } return self; } - (void)drawRect:(CGRect)rect { // override the standard background with our own custom one UIImage *image = [[UIImage imageNamed:@"navigation_bar_bgd.png"] retain]; [image drawInRect:rect]; [image release]; } #pragma mark - #pragma mark UINavigationDelegate Methods - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ // use the title of the passed in view controller NSString *title = [viewController title]; // create our own UILabel with custom color, text, etc UILabel *titleView = [[UILabel alloc] init]; [titleView setFont:[UIFont boldSystemFontOfSize:18]]; [titleView setTextColor:[UIColor blackColor]]; titleView.text = title; titleView.backgroundColor = [UIColor clearColor]; [titleView sizeToFit]; viewController.navigationItem.titleView = titleView; [titleView release]; viewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.1 green:0.2 blue:0.3 alpha:0.8]; } - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ } - (void)dealloc { [super dealloc]; } @end I know that I can use a category to change the background image, but i still want to be able to set the text color of the navigation bar title @implementation UINavigationBar (CustomImage) - (void)drawRect:(CGRect)rect { UIImage *image = [UIImage imageNamed: @"navigation_bar_bgd.png"]; [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; } @end any suggestions or other solutions? I basically want to create a light background and dark text like Flickr's app navigation bars

    Read the article

  • UISearchBar and UINavigationItem

    - by tbehunin
    I can't seem to get a UISearchBar to position itself from the far left to the far right in the navigation bar. In the -(void)viewDidLoad method, I have the following code: `UISearchBar *sb = [[UISearchBar alloc] initWithFrame:self.tableView.tableHeaderView.frame]; sb.delegate = self; self.navigationItem.titleView = sb; [sb sizeToFit]; [sb release];` When you build and run, it looks just fine at first glance. However, looking more closely, you can tell there is a margin/space on the left. This wouldn't be a big deal in the grand scheme of things, but when I tap the search bar to start a search, I animate the cancel button into view. Because the search bar is positioned slightly to the right, the animation is jerky and the cancel button falls off the end like so: link text It seems as if the UINavigationItem is like a table with three cells, where there is a padding on the first and last which I can't remove - nor does there seem to be a way to 'merge' it all together and then place the search bar there. I know this look is possible, because the AppStore search has a search bar in the navigation bar and it goes all the way to the edges. Anyone know how to get the search bar to go all the way to the edges so my slide-in cancel button animation will work properly?

    Read the article

  • Automatically Sizing UIView after Adding to Window

    - by Kristopher Johnson
    I have an iPad app that switches between different views in its main window. The view-switching code looks like this: - (void)switchToViewController:(UIViewController*)viewController { if (currentViewController != viewController) { [currentViewController.view removeFromSuperview]; currentViewController = viewController; [window addSubview:viewController.view]; } } The problem is that when the new view (a UISplitView) appears in landscape orientation, it is not sized to fill the entire window. There is an empty black space on the right. If I rotate the device and then rotate back, the view sizes itself properly. If the device is in portrait orientation, everything works fine. The UISplitView also gets sized properly if it is the first view I show. The problem only occurs if I switch to it after another view has been shown, in landscape. So, is there some way to force iPhone OS to resize the view after it has been added to the window? I've tried calling sizeToFit, but it didn't work. I've also tried setting the view's bounds to the window's bounds, and I've tried setting the frame.

    Read the article

  • How to change rowHeight of a TableViewCell depending on Stringlength

    - by Jens Koehler
    I have a table with different entries, each with different length. The height of each row should fit, so it can show the whole string. I use the following code: //... cellForRowAtIndexPath if (row == 0) { cell = [tableView dequeueReusableCellWithIdentifier:@"affCell"]; //if (!cell) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"affCell"]autorelease]; cell.accessoryType = UITableViewCellAccessoryNone; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.autoresizingMask = UIViewAutoresizingFlexibleHeight; affL = [[UILabel alloc] initWithFrame:CGRectZero]; affL.textAlignment = UITextAlignmentLeft; affL.autoresizingMask = UIViewAutoresizingFlexibleHeight; [cell.contentView addSubview:affL]; //} //declaration label affL.text = [fDictionary objectForKey:@"aff"]; affL.numberOfLines = 0; [affL sizeToFit]; affL.frame = CGRectMake(15.0, 10.0, 220.0, affL.frame.size.height); CGFloat affLH = affL.frame.size.height; [tableView setRowHeight:affLH+30]; I also use //... heightForRowAtIndexPath return affL.frame.size.height; How can I fix this problem?

    Read the article

  • How would you design a question/answer view (iPhone SDK)

    - by Aurélien Vallée
    I'm new to iPhone development, and I have a question on how to create a view for my application. The view should display a problem (using formatted/syntax highlighted text), and multiple possible answers. The user should be able to click on an answer to validate it. Currently, I am trying to use a UITableView embedding UIWebView as contentView. That allows me to display formatted text easily. The problem is that it is a real pain to compute and adjust the height of the cells. I have to preload the webview, call sizeToFit, get its height, and update the cell accordingly. This process should be done for the problem and the answers (as they are HTML formatted text too). It's such a pain that I am planning to switch to something else. I thought using only a big UIWebView and design everything in HTML. But I looked at some articles describing how to communicate between the HTML page and the ObjectiveC code. This seems to involve some awful tricks too... So... that's it, I don't really know what I should do. I guess some of you dealt with such things before, and would provide some greatly appreciated tips :)

    Read the article

  • How to get height for NSAttributedString at a fixed width

    - by bonaldi
    I want to do some drawing of NSAttributedStrings in fixed-width boxes, but am having trouble calculating the right height they'll take up when drawn. So far, I've tried: Calling - (NSSize) size, but the results are useless (for this purpose), as they'll give whatever width the string desires. Calling - (void)drawWithRect:(NSRect)rect options:(NSStringDrawingOptions)options with a rect shaped to the width I want and NSStringDrawingUsesLineFragmentOrigin in the options, exactly as I'm using in my drawing. The results are ... difficult to understand; certainly not what I'm looking for. (As is pointed out in a number of places, including this Cocoa-Dev thread). Creating a temporary NSTextView and doing: [[tmpView textStorage] setAttributedString:aString]; [tmpView setHorizontallyResizable:NO]; [tmpView sizeToFit]; When I query the frame of tmpView, the width is still as desired, and the height is often correct ... until I get to longer strings, when it's often half the size that's required. (There doesn't seem to be a max size being hit: one frame will be 273.0 high (about 300 too short), the other will be 478.0 (only 60-ish too short)). I'd appreciate any pointers, if anyone else has managed this.

    Read the article

1 2  | Next Page >