IOS圖片的原生(Graphics)詳解及實例
更新時間:2017年05月16日 11:08:41 投稿:lqh
這篇文章主要介紹了IOS圖片的原生(Graphics)詳解及實例的相關(guān)資料,需要的朋友可以參考下
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. }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
iOS應(yīng)用中使用Auto Layout實現(xiàn)自定義cell及拖動回彈
這篇文章主要介紹了iOS應(yīng)用中使用Auto Layout實現(xiàn)自定義cell及拖動回彈的方法,自定義UITableViewCell并使用Auto Layout對其進行約束可以方便地針對多尺寸屏幕進行調(diào)整,代碼為Swift語言,需要的朋友可以參考下2016-03-03OC runtime學(xué)習(xí)筆記之關(guān)聯(lián)對象
這篇文章主要介紹了OC runtime學(xué)習(xí)筆記之關(guān)聯(lián)對象的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-09-09iOS overFullScreen與fullScreen區(qū)別分析
這篇文章主要介紹了iOS overFullScreen與fullScreen區(qū)別分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-11-11iOS 使用Moya網(wǎng)絡(luò)請求的實現(xiàn)方法
這篇文章主要介紹了iOS 使用Moya網(wǎng)絡(luò)請求的實現(xiàn)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-07