ios之如何让图片显示成圆形的样式/设置控件边框大小以及颜色
来源:互联网 发布:淘宝我的爱车档案修改 编辑:程序博客网 时间:2024/05/03 13:38
比如说QQ登陆头像显示出来的就是圆形的,但实际上它的图片并非就是圆形,而是通过对layer层进行绘制而成的。说到layer每个控件都会有layer层属性所以可以把任意的控件都可以设置成圆形,或是椭圆型看项目需要而定
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"头像.png"]]; imageView.frame = CGRectMake(100, 100, 100, 100); // 通过layer层设置控件的边角半径(每个控件都会有一个layer层所有其他控件也都能实现圆形效果) imageView.layer.cornerRadius = 50; // 同时也要设置超出部分不让显示 这样就可以达到一个圆形的效果图片- imageView.clipsToBounds = YES; [mainView.view addSubview:imageView];
再来看看layer层还带有什么属性,可以设置什么效果呢,一个是可以设置控件的边框大小以及颜色,有时候可以方便我们对项目控件的测试说白了也就是更加清晰显示出控件的位置把比如说tableView 的cell 设置后可以很清楚看到每个cell的大小范围,其次还可以实现点击让控件有选中的效果,更加高级点就是通过layer层对控件进行动画的绘制
下面是苹果API
@property CGFloat cornerRadius; //设置边角半径/* The width of the layer's border, inset from the layer bounds. The * border is composited above the layer's content and sublayers and * includes the effects of the `cornerRadius' property. Defaults to * zero. Animatable. */@property CGFloat borderWidth; // 设置控件的边框宽度/* The color of the layer's border. Defaults to opaque black. Colors * created from tiled patterns are supported. Animatable. */@property CGColorRef borderColor; // 设置控件的边框颜色/* The opacity of the layer, as a value between zero and one. Defaults * to one. Specifying a value outside the [0,1] range will give undefined * results. Animatable. */@property float opacity; // 设置控件的透明度有部分动画会用到/* When true, and the layer's opacity property is less than one, the * layer is allowed to composite itself as a group separate from its * parent. This gives the correct results when the layer contains * multiple opaque components, but may reduce performance. * * The default value of the property is read from the boolean * UIViewGroupOpacity property in the main bundle's Info.plist. If no * value is found in the Info.plist the default value is YES for * applications linked against the iOS 7 SDK or later and NO for * applications linked against an earlier SDK. */
// 只需要这两句话就可以设置完成 imageView.layer.borderWidth = 2; // float类型数据 imageView.layer.borderColor = [UIColor redColor].CGColor; // 颜色需要是CGColor
1 0
- ios之如何让图片显示成圆形的样式/设置控件边框大小以及颜色
- 如何设置Button控件的边框颜色
- 设置控件边框的样式
- 自定义控件---带边框的圆形图片
- IOS 应用/游戏项目应该如何灵活封装 控件显示样式与项目颜色的公用
- 圆形的图片边框
- html设置字体显示颜色以及大小
- Android 圆形left,right,bottom三边框的颜色设置
- binbinyang-----Glide用在CircleImageView上显示默认图片的问题,以及Glide让imageview自动显示成圆形头像
- iOS之XIB设置边框颜色属性
- 让控件显示边框
- edit控件中如何设置字体的颜色,并把一行文字设置成不同大小。
- table 边框显示设置和js显示无图片样式
- iOS Quartz2D - 裁剪图片为带边框的圆形图片
- Android中如何让图片自适应控件的大小
- Word中如何设置表格的边框线样式和颜色
- iOS设置view的边框、圆角、颜色
- iOS开发之设置UIView边框颜色及边线厚度以及圆角及弧度
- Hadoop,MapReduce操作Mysql
- giubbotti woolrich the outcome will happen
- 意外关闭Eclipse导致无法启动的解决办法
- 多喝水对前列腺炎的康复有帮助
- 安卓图表引擎AChartEngine(三) - 示例源码折线图、饼图和柱状图
- ios之如何让图片显示成圆形的样式/设置控件边框大小以及颜色
- asp.net 跨域单点登录
- 建立第一个directX程序——在C#下利用DirectSound实现声音播放
- Android ViewPager
- CXF 开发 WebService
- 乱七八糟技术论坛
- 字符串太长,怎么在编译器中换一行再写?
- sql将一张表的一列更新到另一张表中
- 程序调试