Paintcode为自定义按钮生成iOS代码(不工作)

时间:2014-03-09 15:48:00

标签: ios custom-controls paint-code

我正在使用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];

1 个答案:

答案 0 :(得分: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];
}