Как получить черную линию на прозрачном UIView
Я должен нарисовать черную линию на прозрачном UIView, но, несмотря на то, что установил альфа линии равной 1, однако это принимает степень прозрачности UIView. Как я могу сделать?
#import <UIKit/UIKit.h>
@interface FinalAlgView : UIView{
@private
//....
CGFloat lineWidth;
UIColor *lineColor;
UIImage *curImage;
CGMutablePathRef path;
}
@property (nonatomic, retain) UIColor *lineColor;
@property (readwrite) CGFloat lineWidth;
@property (assign, nonatomic) BOOL empty;
в реализации
#define DEFAULT_COLOR [UIColor colorWithRed:127.0/255.0 green:255.0/255.0 blue:0/255.0 alpha:0.6];
#define DEFAULT_WIDTH 20.0f
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.frame = CGRectMake(0, 0, 1024, 768);
self.lineWidth = DEFAULT_WIDTH;
self.lineColor = DEFAULT_COLOR;
self.empty = YES;
path = CGPathCreateMutable();
self.alpha=0.3;
self.opaque = NO;
}
return self;
}
- (void)drawRect:(CGRect)rect {
[[UIColor grayColor] set];
UIRectFill(rect);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddPath(context, path);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, self.lineWidth);
CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
CGContextStrokePath(context);
self.empty = NO;
}
1 ответ
Вы должны поместить настройку альфа UIView в drawRect, а не в initWithFrame
НЕТ
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.alpha=0.3;
}
return self;
}
ДА
- (void)drawRect:(CGRect)rect {
[[UIColor colorWithRed:200.0/225.0 green:200.0/255.0 blue:200.0/255.0 alpha:0.0]set];
}