您的位置:首页 > 其它

绘制渐变矩形的一种方法

2015-09-05 03:25 375 查看
- (void)drawRect:(CGRect)rect {
// Drawing code
[super drawRect:rect];

//draw wings
[[UIColor blackColor] set];
CGFloat tempYPlace = self.currentSelectionY;
if (tempYPlace < 0.0) {
tempYPlace = 0.0;
} else if (tempYPlace >= self.frame.size.height) {
tempYPlace = self.frame.size.height - 1.0;
}
CGRect temp = CGRectMake(0.0, tempYPlace, self.frame.size.width, 1.0);
UIRectFill(temp);

//draw central bar over it
CGFloat cbxbegin = self.frame.size.width * 0.2;
CGFloat cbwidth = self.frame.size.width * 0.6;
for (int y = 0; y < self.frame.size.height; y++) {
[[UIColor colorWithHue:(y/self.frame.size.height) saturation:1.0 brightness:1.0 alpha:1.0] set];
CGRect temp = CGRectMake(cbxbegin, y, cbwidth, 1.0);
UIRectFill(temp);
}
}


如图所示:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: