如何制作既有图像又有标题的UIButton?

时间:2015-03-28 14:23:06

标签: ios uibutton uiimage title

我想为aUIButton设置图片和标题。当我使用按钮的背景图像时,这两个都可见。但是当我使用setImage方法时,标题就不再可见了。

[self setBackgroundColor:[UIColor clearColor]];
    [self setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 80.0, 0.0, 0.0)];
    [self setTitle:@"Kansal Ji" forState:UIControlStateNormal];
    [self setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.titleLabel setBackgroundColor:[UIColor blueColor]];

    [self setImage:[UIImage imageNamed:@"categories.png"] forState:UIControlStateNormal];
    [self.imageView setBackgroundColor:[UIColor greenColor]];
    [self setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, 0.0,kWidthOfView(self)-kHeightOfView(self))];
    self.clipsToBounds = YES;

请帮助解决此问题。以下代码在UIButton的子类中完成。

0 个答案:

没有答案