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

