在UIButton内添加一个图像作为附件 [英] Add an image inside UIButton as an accesory
问题描述
我有以下 UIButton
我想在最右侧添加一个图像。像 accessoryView
我已经使用backgroundImage,我想避免将2个图像合并为1。 p>
可以在UIButton中添加另一个图像,这是一个 AccesoryView
让说有一个 PLUS
到最右边? (我正在寻找一种在Button内插入新图片的方法)
@luisCien评论
[_addImage setImage:[UIImage imageNamed:@shareMe] forState:UIControlStateNormal];
_addImage.contentHorizontalAlignment =
UIControlContentHorizontalAlignmentRight;
它看起来像这样,我想要的图像在文本的右边。
只需将其添加为子视图并选择您的坐标即可。
UIImageView * yourPlusSign = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@yourPlusSignImageTitle]];
yourPlusSign.frame = CGRectMake(x,y,width,height); //选择适当地放在baseButton框架中的值
//或者获取你的BASEButton的宽度和高度并相应地改变
yourPlusSign.contentMode = UIViewContentModeScaleAspectFill; //或任何模式最适合你
[yourBaseButton addSubview:yourPlusSign];
I have the following UIButton
I want to add an Image inside to the far right. Like an accessoryView
I am already using backgroundImage and I want to avoid combining the 2 images into 1.
Is it possible to add another image inside the UIButton that is an AccesoryView
lets say an image that has a PLUS
to the far right? ( I am looking to a way to insert the new image inside the Button)
@luisCien comment
I tried
[_addImage setImage:[UIImage imageNamed:@"shareMe"] forState:UIControlStateNormal];
_addImage.contentHorizontalAlignment =
UIControlContentHorizontalAlignmentRight;
and it looks like this, I would like to image to be on the right side of the text.
Just add it as a subview and choose your coordinates..Try something like this:
UIImageView *yourPlusSign = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"yourPlusSignImageTitle"]];
yourPlusSign.frame = CGRectMake(x, y, width, height);//choose values that fit properly inside the frame of your baseButton
//or grab the width and height of yourBaseButton and change accordingly
yourPlusSign.contentMode=UIViewContentModeScaleAspectFill;//or whichever mode works best for you
[yourBaseButton addSubview:yourPlusSign];
这篇关于在UIButton内添加一个图像作为附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!