使用setImage方法;
- (void)setImage:(UIImage *)image forState:(UIControlState)state
所以,你的代碼將是;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(goToGeoloc) forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(245.0, 8.0, 45.0, 45.0);
UIImage *image = [UIImage imageNamed:@"ico_plan.png"];
[button setImage:image forState:UIControlStateNormal];
或者我還想讓你的文本顯示使用;
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
這將導致;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(goToGeoloc) forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(245.0, 8.0, 45.0, 45.0);
UIImage *image = [UIImage imageNamed:@"ico_plan.png"];
[button setBackgroundImage:image forState:UIControlStateNormal];
UIButton documentation; http://bit.ly/kruq5y
Whta是setBackground和setImage之間的區別? – izan 2011-05-04 08:29:25
這是2015年...谷歌和StackOverflow正在取代文件。 – quemeful 2015-02-12 14:32:28