我有自己的子类UIButton.我添加UIImageView它并添加图像.我想用浅色涂在图像上,但它不起作用.
到目前为止,我有:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.clipsToBounds = YES;
self.circleView = [[UIView alloc]init];
self.circleView.backgroundColor = [UIColor whiteColor];
self.circleView.layer.borderColor = [[Color getGraySeparatorColor]CGColor];
self.circleView.layer.borderWidth = 1;
self.circleView.userInteractionEnabled = NO;
self.circleView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:self.circleView];
self.iconView = [[UIImageView alloc]init];
[self.iconView setContentMode:UIViewContentModeScaleAspectFit];
UIImage * image = [UIImage imageNamed:@"more"];
[image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.iconView.image = image;
self.iconView.translatesAutoresizingMaskIntoConstraints = NO;
[self.circleView addSubview:self.iconView];
...
Run Code Online (Sandbox Code Playgroud)
并在选择:
- (void) setSelected:(BOOL)selected
{
if (selected) {
[self.iconView setTintColor:[UIColor redColor]]; …Run Code Online (Sandbox Code Playgroud) 我用图像创建了一个名为"button"的UIButton实例[UIButton setImage:forState:].button.frame大于图像的大小.
现在我想缩小此按钮的图像.我试图改变button.imageView.frame,button.imageView.bounds和button.imageView.contentMode,但都显得无效.
任何人都可以帮助我缩放图像UIButton视图吗?
我创建了UIButton这样的:
UIButton *button = [[UIButton alloc] init];
[button setImage:image forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
我试图像这样缩放图像:
button.imageView.contentMode = UIViewContentModeScaleAspectFit;
button.imageView.bounds = CGRectMake(0, 0, 70, 70);
Run Code Online (Sandbox Code Playgroud)
还有这个:
button.imageView.contentMode = UIViewContentModeScaleAspectFit;
button.imageView.frame = CGRectMake(0, 0, 70, 70);
Run Code Online (Sandbox Code Playgroud)