안녕하세요 저는 버튼을 개인 설정하는 데 사용하는 UIButton
에서 파생되는 클래스 RqButton
을 가지고 있습니다.initWithFrame으로 다른 인수를 전달하십시오. CGRectMake()
button = [[RqButton alloc] initWithFrame:CGRectMake(xz, yz, sq, sq)];
모든 것이 예상대로 작동하지만 다른 매개 변수를 RqButton
으로 전달하려는 경우 어떻게되는지 모릅니다.
이것은 내 RqButton.m
당신은 내가 CGrect
와 라인에서 사용하기 위해서 INT의 R을 통과하는 동안 클래스를 호출 할 수 있도록하려는 것을 볼
#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
CGFloat endRadius = R;
물론 button = [[RqButton alloc] initWithFrame:CGRectMake(xz, yz, sq, sq) :1];
은 이와 같이 작동하지 않지만 실제로는 실제로 어떻게해야할까요? 당신의 도움에 대한
감사합니다, 알렉스
환호 동료, 완벽한 솔루션을! – user2875404