嘿,我有一个类RqButton
派生自UIButton
,我用它来个性化我的按钮。用initWithFrame传递另一个参数:CGRectMake()
如果如果做button = [[RqButton alloc] initWithFrame:CGRectMake(xz, yz, sq, sq)];
一切都按预期工作,但我想通过另一个参数RqButton
,我不知道如何。
这是我RqButton.m
#import "RqButton.h"
@implementation RqButton
+ (RqButton *)buttonWithType:(UIButtonType)type
{return [super buttonWithType:UIButtonTypeCustom];}
- (void)drawRect:(CGRect)rect r:(int)r
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
float width = CGRectGetWidth(rect);
float height = CGRectGetHeight(rect);
UIColor *borderColor = [UIColor colorWithRed:0.99f green:0.95f blue:0.99f alpha:1.00f];
CGFloat BGLocations[2] = { 0.0, 1.0 };
CGFloat BgComponents[8] = { 0.99, 0.99, 0.0 , 1.0,
0.00, 0.00, 0.00, 1.0 };
CGColorSpaceRef BgRGBColorspace = CGColorSpaceCreateDeviceRGB();
CGGradientRef bgRadialGradient = CGGradientCreateWithColorComponents(BgRGBColorspace, BgComponents, BGLocations, 2);
UIBezierPath *roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(0, 0, width, height) cornerRadius: 5];
[roundedRectanglePath addClip];
CGPoint startBg = CGPointMake (width*0.5, height*0.5);
CGFloat endRadius= r;
CGContextDrawRadialGradient(ctx, bgRadialGradient, startBg, 0, startBg, endRadius, kCGGradientDrawsAfterEndLocation);
CGColorSpaceRelease(BgRGBColorspace);
CGGradientRelease(bgRadialGradient);
[borderColor setStroke];
roundedRectanglePath.lineWidth = 2;
[roundedRectanglePath stroke];
}
@end
你看,我希望能够调用类,而经过CGrect
,为了在该行使用它INT R CGFloat的endRadius = R;
当然,button = [[RqButton alloc] initWithFrame:CGRectMake(xz, yz, sq, sq) :1];
不会像这样工作,但现在,真正做到这一点的方式是什么?
感谢您的帮助,亚历克斯
干杯伴侣,完美的解决方案! – user2875404 2014-09-04 16:57:53