我想在图像下方添加一个同时包含图像和文字,文字的按钮。任何人都可以指导我。我在UIScrollview中以编程方式添加按钮。感谢
答案 0 :(得分:2)
下面的代码表示在Objective C中以编程方式创建UIButton
的一种方法。
UIButton *mButton = [UIButton buttonWithType:UIButtonTypeCustom];
[mButton addTarget:self action:@selector(clickedMe:) forControlEvents:UIControlEventTouchUpInside];
[mButton setBackgroundImage:[UIImage imageNamed:@"yourImage.png"] forState:UIControlStateNormal];
[mButton setTitle:@"Show View" forState:UIControlStateNormal];
mButton.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[yourScrollView addSubview:mButton];
答案 1 :(得分:1)
如果您使用的是Interface Builder ,有一种非常简单的方法:
示例:
OR
您甚至可以通过代码使用相同的方法,而不像其他解决方案那样在内部创建UILabel和UIImage。
OR
[btn setBackgroundImage:buttonImage forState:UIControlStateNormal];