我有一个横幅导航视图。我添加了一个我添加的自定义按钮:
- (id) initWithNotification:(JCNotificationBanner*)notification {
self = [super init];
if (self) {
isPresentedMutex = [NSObject new];
self.backgroundColor = [UIColor clearColor];
self.iconImageView = [UIImageView new];
self.iconImageView.image = [UIImage imageNamed:@"close.png"];
[self addSubview:self.iconImageView];
self.titleLabel = [UILabel new];
self.titleLabel.font = [UIFont boldSystemFontOfSize:16];
self.titleLabel.textColor = [UIColor lightTextColor];
self.titleLabel.backgroundColor = [UIColor clearColor];
[self addSubview:self.titleLabel];
self.messageLabel = [UILabel new];
self.messageLabel.font = [UIFont systemFontOfSize:14];
self.messageLabel.textColor = [UIColor lightTextColor];
self.messageLabel.backgroundColor = [UIColor clearColor];
self.messageLabel.numberOfLines = 0;
[self addSubview:self.messageLabel];
// Button
_detailDisclosureButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_detailDisclosureButton setBackgroundImage:[UIImage imageNamed:@"disclosure.png"] forState:UIControlStateNormal];
[_detailDisclosureButton setBackgroundImage:nil forState:UIControlStateSelected];
// _detailDisclosureButton.hidden = NO;
[_detailDisclosureButton addTarget:self action:@selector(detailDisclosureButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[_detailDisclosureButton setEnabled:YES];
[self addSubview:_detailDisclosureButton];
UITapGestureRecognizer* tapRecognizer;
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleTap:)];
[self addGestureRecognizer:tapRecognizer];
self.notificationBanner = notification;
}
return self;
}
这是我的绘制上下文方法正在调用的内容。
- (void) drawRect:(CGRect)rect {
CGRect bounds = self.bounds;
CGFloat lineWidth = kJCNotificationBannerViewOutlineWidth;
CGFloat radius = 10;
CGFloat height = bounds.size.height;
CGFloat width = bounds.size.width;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetAllowsAntialiasing(context, true);
CGContextSetShouldAntialias(context, true);
CGMutablePathRef outlinePath = CGPathCreateMutable();
CGPathMoveToPoint(outlinePath, NULL, lineWidth, 0);
CGPathAddLineToPoint(outlinePath, NULL, lineWidth, height - radius - lineWidth);
CGPathAddArc(outlinePath, NULL, radius + lineWidth, height - radius - lineWidth, radius, -M_PI, M_PI_2, 1);
CGPathAddLineToPoint(outlinePath, NULL, width - radius - lineWidth, height - lineWidth);
CGPathAddArc(outlinePath, NULL, width - radius - lineWidth, height - radius - lineWidth, radius, M_PI_2, 0, 1);
CGPathAddLineToPoint(outlinePath, NULL, width - lineWidth, 0);
CGContextSetRGBFillColor(context, 0, 0, 0, 0.9);
CGContextAddPath(context, outlinePath);
CGContextFillPath(context);
CGContextAddPath(context, outlinePath);
CGContextSetRGBFillColor(context, 0, 0, 0, 1);
CGContextSetLineWidth(context, lineWidth);
CGContextDrawPath(context, kCGPathStroke);
CGPathRelease(outlinePath);
}
我的排列框架的布局子视图方法如下:
- (void) layoutSubviews {
if (!(self.frame.size.width > 0)) { return; }
BOOL hasTitle = notificationBanner ? (notificationBanner.title.length > 0) : NO;
CGFloat borderY = kJCNotificationBannerViewOutlineWidth + kJCNotificationBannerViewMarginY;
CGFloat borderX = kJCNotificationBannerViewOutlineWidth + kJCNotificationBannerViewMarginX;
CGFloat currentX = borderX;
CGFloat currentY = borderY;
CGFloat contentWidth = self.frame.size.width - (borderX * 2.0);
currentY += 2.0;
if (hasTitle) {
self.titleLabel.frame = CGRectMake(currentX, currentY, contentWidth, 22.0);
currentY += 22.0;
}
self.messageLabel.frame = CGRectMake(currentX, currentY, contentWidth, (self.frame.size.height - borderY) - currentY);
[self.messageLabel sizeToFit];
CGRect messageFrame = self.messageLabel.frame;
CGFloat spillY = (currentY + messageFrame.size.height + kJCNotificationBannerViewMarginY) - self.frame.size.height;
if (spillY > 0.0) {
messageFrame.size.height -= spillY;
self.messageLabel.frame = messageFrame;
}
_detailDisclosureButton.frame = CGRectMake(285,self.center.y-15,29,29);
}
未调用名为detailDisclosureButtonPressed
的My Button操作方法。请帮我解决这个问题?