右侧底部的uibutton图像设置

时间:2010-12-29 11:42:31

标签: iphone xcode

我有框架按钮(0,0,120,100),我想在按钮右侧添加图像 .i想要在按钮底部的右侧添加我想要的尺寸(10,10)的图像。

如何做到这一点。我用谷歌搜索但可以净化它。

2 个答案:

答案 0 :(得分:6)

我的回答是假设我有uibutton roundedButtonType代码如下

        roundedButtonType = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
    [roundedButtonType setImageEdgeInsets:UIEdgeInsetsMake(-10.00, 5.00, -5.00, 0.00)];

通过这样做,我无法在按钮上获得设置图像,无论我想要按钮。

通过先设置按钮的背景图像,图像会变得拉伸。所以我使用上面的代码来获取更大区域(在按钮上)的点击事件,这解决了我的问题。

答案 1 :(得分:3)

代码如下,

UIButton *imageBut=[[UIButton alloc]initWithFrame:CGRectMake(x, y, 120, 100)];
UIImageView *img=[[UIImageView alloc] initWithFrame:CGRectMake(110, 90, 10, 10)];
img.userInteractionEnabled=NO;
[imageBut addSubview:img];
[self.view addSubview:imageBut];

x,y是视图中按钮的位置。