在UIButton内添加一个图像作为附件 [英] Add an image inside UIButton as an accesory

查看:100
本文介绍了在UIButton内添加一个图像作为附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 UIButton 我想在最右侧添加一个图像。像 accessoryView



我已经使用backgroundImage,我想避免将2个图像合并为1。 p>

可以在UIButton中添加另一个图像,这是一个 AccesoryView 让说有一个 PLUS 到最右边? (我正在寻找一种在Button内插入新图片的方法)





@luisCien评论





  [_addImage setImage:[UIImage imageNamed:@shareMe] forState:UIControlStateNormal]; 
_addImage.contentHorizo​​ntalAlignment =
UIControlContentHorizo​​ntalAlignmentRight;

它看起来像这样,我想要的图像在文本的右边。

解决方案

只需将其添加为子视图并选择您的坐标即​​可。

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆