首页 > 代码库 > image的原生
image的原生
效果图:
代码:
- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 44, 44)]; imageView.image=[self defaultImage]; [self.view addSubview:imageView]; }-(UIImage *)defaultImage { static UIImage *defaultImage = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ UIGraphicsBeginImageContextWithOptions(CGSizeMake(20.f, 13.f), NO, 0.0f); [[UIColor blackColor] setFill]; [[UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 20, 1)] fill]; [[UIBezierPath bezierPathWithRect:CGRectMake(0, 5, 20, 1)] fill]; [[UIBezierPath bezierPathWithRect:CGRectMake(0, 10, 20, 1)] fill]; [[UIColor whiteColor] setFill]; [[UIBezierPath bezierPathWithRect:CGRectMake(0, 1, 20, 2)] fill]; [[UIBezierPath bezierPathWithRect:CGRectMake(0, 6, 20, 2)] fill]; [[UIBezierPath bezierPathWithRect:CGRectMake(0, 11, 20, 2)] fill]; defaultImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); }); return defaultImage;}
image的原生
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。