我想创建一个带有自定义图像(背景图像)的按钮,我已经做到了。 如何将 ImageView 分配给可能的按钮?
感谢您的回答
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"];
UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
最佳答案
你想要的是:
[button setBackgroundImage:image forState:UIControlStateNormal];
或
[button setImage:image forState:UIControlStateNormal];
关于ios - ImageView 和 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5880478/