IOS图片的原生(Graphics)详解及实例
程序员文章站
2023-12-19 19:07:34
ios图片的原生(graphics)详解及实例
一,效果图。
二,工程图。
三,代码。
rootviewcontroller.h
#import...
ios图片的原生(graphics)详解及实例
一,效果图。
二,工程图。
三,代码。
rootviewcontroller.h
#import <uikit/uikit.h> @interface rootviewcontroller : uiviewcontroller @end
rootviewcontroller.m
#import "rootviewcontroller.h" @interface rootviewcontroller () @end @implementation rootviewcontroller - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; // do any additional setup after loading the view. //背景图 [self addview]; } #pragma -mark -functions //背景图 -(void)addview { 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; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of any resources that can be recreated. }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!