IOS圖片的原生(Graphics)詳解及實(shí)例
更新時間:2017年05月16日 11:08:41 投稿:lqh
這篇文章主要介紹了IOS圖片的原生(Graphics)詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下
IOS圖片的原生(Graphics)詳解及實(shí)例
一,效果圖。

二,工程圖。

三,代碼。
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)文章
深入理解Objective-C中類的數(shù)據(jù)結(jié)構(gòu)
最近發(fā)現(xiàn)用Objective-C確實(shí)好容易,下面這篇文章主要給大家介紹了關(guān)于Objective-C中類的數(shù)據(jù)結(jié)構(gòu)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-05-05
iOS tableView右側(cè)索引視圖狀態(tài)獲取的方法實(shí)例
tableView用于顯示一個垂直滾動的單元格數(shù)(通常為可重復(fù)使用的單元格)組成的視圖,這篇文章主要給大家介紹了關(guān)于iOS tableView右側(cè)索引視圖狀態(tài)獲取的相關(guān)資料,需要的朋友可以參考下2021-07-07
iOS開發(fā)上下滑動UIScrollview隱藏或者顯示導(dǎo)航欄的實(shí)例
下面小編就為大家分享一篇iOS開發(fā)上下滑動UIScrollview隱藏或者顯示導(dǎo)航欄的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01
IOS LaunchScreen設(shè)置啟動圖片與啟動頁停留時間詳解
這篇文章主要介紹了IOS LaunchScreen設(shè)置啟動圖片與啟動頁停留時間詳解的相關(guān)資料,需要的朋友可以參考下2017-02-02
iOS 標(biāo)簽Tag列表的實(shí)現(xiàn)代碼
這篇文章主要介紹了本篇文章主要介紹了iOS 標(biāo)簽Tag列表的實(shí)現(xiàn)代碼,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-04-04
iOS開發(fā)之UIPickerView實(shí)現(xiàn)城市選擇器的步驟詳解
這篇文章給大家介紹iOS利用控件UIPickerView實(shí)現(xiàn)城市選擇器的效果,選擇城市這一功能相信在大家日常開發(fā)的時候經(jīng)常遇見,下面就來看看詳細(xì)的實(shí)現(xiàn)過程,有需要的可以參考借鑒。2016-09-09

