ios学习第六天(二)自定义UIView中
来源:互联网 发布:js history 清除 编辑:程序博客网 时间:2024/06/16 09:53
这次用自定义view创造一个不存在的view,看效果图
这个就是了,但是我不知道背景怎么是黑色的,好丑,经过探索后发现在外边设置背景颜色即可,设置成透明色。
来不及解释了,快看代码:
//// MyCircleView.m// MyUIView//// Created by Moluth on 17/4/12.// Copyright (c) 2017年 Moluth. All rights reserved.//#import "MyCircleView.h"@implementation MyCircleView-(void)drawRect:(CGRect)rect{ //绘画区域 CGRect bounds = [self bounds]; // 中心点 CGPoint center; center.x = bounds.origin.x + bounds.size.width / 2.0; center.y = bounds.origin.y + bounds.size.height / 2.0; // 为了不超过图像的边缘,计算最大的半径 float mr = hypot(bounds.size.width, bounds.size.height) / 2.0; // 获取图形绘制上下文 CGContextRef context = UIGraphicsGetCurrentContext(); //线条宽度是20 CGContextSetLineWidth(context, 15);//线条粗细 //循环绘制圆 for (float r = mr-30; r > 0; r -= 10) { // 设置线条颜色 [[[UIColor alloc] initWithRed:(sin(r)+1.0)/2.0 green:(cos(r*127.0+2.0)+1.0)/2.0 blue:(cos(r)+1.0)/2.0 alpha:0.5] setStroke]; CGContextAddArc(context, center.x, center.y,r, 0.0, M_PI * 2.0, YES);//添加弧型路径 CGContextStrokePath(context);//绘制路径 } }@end
给大家推荐一篇文章,写的很不错:http://blog.csdn.net/rhljiayou/article/details/9919713
0 0
- ios学习第六天(二)自定义UIView中
- ios学习第六天(一)自定义UIView上
- ios学习第六天(三)自定义UIView下
- ios学习第六天(四)美丽的自定义View
- iOS中标准的自定义控件(UIView的封装)
- iOS中视图控制器指定自定义UIView
- iOS中UIView的用法(二)
- iOS自定义弹窗(UIView)
- ios自定义UIView
- ios 自定义uiview
- iOS入门(二十四)UIView
- IOS学习之路(二十五)UIView动画,弹出后移动然后消失
- iOS 开发学习之 User Interface(5)UIView 与 UIViewController【二】
- IOS 开发学习二十三 手势 切换UIView
- 学习iOS的第六天
- UIView Animation 学习笔记(二)
- IOS学习笔记(三)UIView animation
- iOS学习--UIView详解~~~~~
- easyui messager show和confirm
- NRF52832NFC读写
- HashMap根据Value值的大小排序
- win7系统右键菜单没有新建word功能的解决方法
- 事件驱动的Python实现
- ios学习第六天(二)自定义UIView中
- Ubuntu14.04 编译 Android4.4.4
- easyui datagrid loadFilter loadData
- Java学习之数组操作
- flex amcharts demo
- 根据ip获取城市
- Construct the Rectangle
- flex amcharts line demo2
- CentOS6.8安装rabbitmq