9

我想制作一个圆角不倾斜的可拉伸按钮。目前我正在以编程方式这样做:

[self.myButton setImage:[[UIImage imageNamed:@"my-button"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4)] forState:UIControlStateNormal];

有什么方法可以在 IB 中做到这一点,并且让我不必为所有按钮创建插座并viewDidLoad用上面的调用乱扔我的方法?

4

1 回答 1

1

No. There isn't currently a way to achieve that.

You can however subclass UIButton and override drawRect:

- (void)drawRect:(CGRect)rect
{
    UIImage *textFieldBackground = [[UIImage imageNamed:@"my-button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4)];
    [textFieldBackground drawInRect:[self bounds]];
} 
于 2012-09-04T03:20:10.743 回答