Skip to main content

Posts

Showing posts with the label uibutton

Is it even possible to change a UIButtons background color?

This one has me stumped. Is it possible at all to change the background color of a UIButton in Cocoa for iPhone. I've tried setting the background color but it only changes the corners. setBackgroundColor: seems to be the only method available for such things. [random setBackgroundColor:[UIColor blueColor]]; [random.titleLabel setBackgroundColor:[UIColor blueColor]];

UIButton of type UIButtonTypeCustom will not display Title (iPhone)

I must have overlooked something completely obvious?? but my button displays its image and size correctly, but I simply can't get the Title to show up. I did a really simple test, the Title does not even show up when I do this: CGRect frameBtn = CGRectMake(160.0f, 150.0f, 144.0f, 42.0f); UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:@"left_halfscreen_button.png"] forState:UIControlStateNormal]; [button setTitle:@"Hello" forState:UIControlStateNormal]; [button setFrame:frameBtn]; NSLog(@"Title:%@", [button currentTitle]); //prints "Title:Hello [self addSubview:button]; I have a factory class that generates custom buttons for me and I thought I messed some detail up there, so I moved the above code directly into my UIView, the title is still blank. Is this a bug or am I simply missing something right in front of my eyes. Thank you for the extra set of eyes:

Setting an image for a UIButton in code

How do you set the image for a UIButton in code? I have this: UIButton *btnTwo = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btnTwo.frame = CGRectMake(40, 140, 240, 30); [btnTwo setTitle:@"vc2:v1" forState:UIControlStateNormal]; [btnTwo addTarget:self action:@selector(goToOne) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btnTwo]; but don't see what will set the image for it. Any help appreciated, Thanks // :)

Minimum sensible button size on iPhone

I'm designing an iPhone app that features a rather large set of onscreen rounded rect buttons. Given finger-based touchscreen UI, what do you think would be the smallest sensible button size? I need to fit as many of them as I can in the viewport without compromising the usability too much. Maybe there's an Apple-recommended minimum size? Right now it's 33x33, and it looked OK on a simulator, but I was playing with the app on a real phone last night, and it was awkward - the buttons felt too small.