iphone - 以编程方式在按钮上添加图像和文本

标签 iphone ios

我想要一个图片和文字“查看详情” 在我的按钮(红色按钮)中以编程方式...... 图像在按钮的左侧,文本在右侧..

UIImage *img = [UIImage imageNamed:@"image.png"];
[aButton setImage:img forState:UIControlStateNormal];
aButton.backgroundColor=[UIColor redColor]; 
//[img release]; i am not sure i release it or not  
//[testBtn setTitleEdgeInsets:UIEdgeInsetsMake(70.0, -150.0, 5.0, 5.0)];
// what the above lines  line work? 
[aButton setTitle:@"View Details" forState:UIControlStateNormal];

我看到按钮但没有,红色按钮...只有红色角...

最佳答案

你制作了带有红色和文本的按钮图像..并在其上设置图像...

这是在按钮上设置图像的代码..

[but1 setImage:[UIImage imageNamed:@"LeftBack.png"] forState:UIControlStateNormal];//在按钮上设置图像。

关于iphone - 以编程方式在按钮上添加图像和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7847794/

相关文章:

iphone - 对象移动后的 CALayer 定位

iphone - 当 View 首次呈现时,UIViewController 中的哪些方法只被调用一次? View 加载?

c++ - iOS 库的 libxml2 链接错误

ios - UIView 从左到右滑动动画有问题?

ios - 检查 View Controller 是否通过动画成功解除

ios - Swift - 通过导航 Controller 进行委托(delegate)

ios - 使用 NSURLSession 获取 JSON 数据

iphone - 使用 UIAppearance 方法自定义 UIAlertView

iphone - AudioServicesPlaySystem声音音量控制

ios - 如果禁用子按钮,则停止将事件传递给父按钮