UIView使用CALayer添加单独一边
2015-11-09 13:13
302 查看
#define kValidDirections [NSArray arrayWithObjects: @"top", @"bottom", @"left", @"right",nil]
- (void) insertLayertoView:(UIView*)sourceView WithRadius:(float)radius Color:(UIColor *)color Directions:(NSArray *)directions
{
// Ignore duplicate direction
NSMutableDictionary *directionDict = [[NSMutableDictionary alloc] init];
for (NSString *direction in directions) [directionDict setObject:@"1" forKey:direction];
for (NSString *direction in directionDict) {
// Ignore invalid direction
if ([kValidDirections containsObject:direction])
{
CAGradientLayer *shadow = [CAGradientLayer layer];
if ([direction isEqualToString:@"top"]) {
[shadow setStartPoint:CGPointMake(0.5, 0.0)];
[shadow setEndPoint:CGPointMake(0.5, 1.0)];
shadow.frame = CGRectMake(0, 0, sourceView.bounds.size.width, radius);
}
else if ([direction isEqualToString:@"bottom"])
{
[shadow setStartPoint:CGPointMake(0.5, 1.0)];
[shadow setEndPoint:CGPointMake(0.5, 0.0)];
shadow.frame = CGRectMake(0, sourceView.bounds.size.height - radius, sourceView.bounds.size.width, radius);
} else if ([direction isEqualToString:@"left"])
{
shadow.frame = CGRectMake(0, 0, radius, sourceView.bounds.size.height);
[shadow setStartPoint:CGPointMake(0.0, 0.5)];
[shadow setEndPoint:CGPointMake(1.0, 0.5)];
} else if ([direction isEqualToString:@"right"])
{
shadow.frame = CGRectMake(sourceView.bounds.size.width - radius, 0, radius, sourceView.bounds.size.height);
[shadow setStartPoint:CGPointMake(1.0, 0.5)];
[shadow setEndPoint:CGPointMake(0.0, 0.5)];
}
shadow.colors = [NSArray arrayWithObjects:(id)[color CGColor], (id)[[UIColor clearColor] CGColor], nil];
[sourceView.layer insertSublayer:shadow atIndex:0];
}
}
}
- (void) insertLayertoView:(UIView*)sourceView WithRadius:(float)radius Color:(UIColor *)color Directions:(NSArray *)directions
{
// Ignore duplicate direction
NSMutableDictionary *directionDict = [[NSMutableDictionary alloc] init];
for (NSString *direction in directions) [directionDict setObject:@"1" forKey:direction];
for (NSString *direction in directionDict) {
// Ignore invalid direction
if ([kValidDirections containsObject:direction])
{
CAGradientLayer *shadow = [CAGradientLayer layer];
if ([direction isEqualToString:@"top"]) {
[shadow setStartPoint:CGPointMake(0.5, 0.0)];
[shadow setEndPoint:CGPointMake(0.5, 1.0)];
shadow.frame = CGRectMake(0, 0, sourceView.bounds.size.width, radius);
}
else if ([direction isEqualToString:@"bottom"])
{
[shadow setStartPoint:CGPointMake(0.5, 1.0)];
[shadow setEndPoint:CGPointMake(0.5, 0.0)];
shadow.frame = CGRectMake(0, sourceView.bounds.size.height - radius, sourceView.bounds.size.width, radius);
} else if ([direction isEqualToString:@"left"])
{
shadow.frame = CGRectMake(0, 0, radius, sourceView.bounds.size.height);
[shadow setStartPoint:CGPointMake(0.0, 0.5)];
[shadow setEndPoint:CGPointMake(1.0, 0.5)];
} else if ([direction isEqualToString:@"right"])
{
shadow.frame = CGRectMake(sourceView.bounds.size.width - radius, 0, radius, sourceView.bounds.size.height);
[shadow setStartPoint:CGPointMake(1.0, 0.5)];
[shadow setEndPoint:CGPointMake(0.0, 0.5)];
}
shadow.colors = [NSArray arrayWithObjects:(id)[color CGColor], (id)[[UIColor clearColor] CGColor], nil];
[sourceView.layer insertSublayer:shadow atIndex:0];
}
}
}
相关文章推荐
- Handler,Looper,Message,MessageQueue,Thread机制的深入理解(举例说明)
- Deploy .Net project automatically with MsBuild and MsDeploy (1)
- 在request中获取项目路径
- UI界面-绝对布局
- UIView,UIButton,UIImageView等设置圆角,设置阴影,设置边框的方法
- iOS [UIScreen mainScreen].scale
- UIView 属性和方法
- FineUI(开源版)v4.2.2发布(8年125个版本,官网示例突破300个)!
- 设置 UISearchBar 输入字体颜色 和 默认字体颜色
- UIalertController日期控件
- AlertDialog.Builder对话框类的用法
- iOS开发 获取手机信息(UIDevice,NSBundle,NSlocale)
- UI界面-表格布局
- 仿58同城UITableViewCell动画
- iOS 下,UILable自适应高度的方法
- 基本的UI控件和布局文件
- MultipartRequest上传文件
- AndroidUI设计——Gridview
- 面试题.自己的总结UI部分(一)
- Builder - 创建者模式