0

我正在使用paintcode为我的应用程序创建圆形按钮。我遵循的步骤是 - 创建为 UIButton 派生的新类,将由paintcode 生成的代码粘贴到 (void)drawRect:(CGRect)rect 中并设置按钮以使用我的自定义类。但我做错了,因为按钮根本没有任何形状,它只是一个标签。这是我使用的代码 -

//// Color Declarations
UIColor* strokeColor = [UIColor colorWithRed: 0 green: 0 blue: 0 alpha: 1];
UIColor* fillColor2 = [UIColor colorWithRed: 0.886 green: 0 blue: 0 alpha: 1];

//// Rounded Rectangle Drawing
UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(44.5, 45.5, 48, 20) cornerRadius: 4];
[fillColor2 setFill];
[roundedRectanglePath fill];
[strokeColor setStroke];
roundedRectanglePath.lineWidth = 1;
[roundedRectanglePath stroke];
4

1 回答 1

0
//// Color Declarations
UIColor* strokeColor = [UIColor colorWithRed: 0 green: 0 blue: 0 alpha: 1];
UIColor* fillColor2 = [UIColor colorWithRed: 0.886 green: 0 blue: 0 alpha: 1];

//// Frames: Set frame to "rect" to have the custom button fit in the UIButton frame
CGRect frame = CGRectMake(45, 45, 48, 20);


//// CustomButton
{
    //// Rounded Rectangle Drawing
    UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(CGRectGetMinX(frame) + 1.5, CGRectGetMinY(frame) + 0.5, CGRectGetWidth(frame) - 3, CGRectGetHeight(frame) - 2) cornerRadius: 4];
    [fillColor2 setFill];
    [roundedRectanglePath fill];
    [strokeColor setStroke];
    roundedRectanglePath.lineWidth = 1;
    [roundedRectanglePath stroke];
}
于 2014-06-01T06:40:42.787 回答