当前位置: 移动技术网 > IT编程>移动开发>IOS > IOS图片的原生(Graphics)详解及实例

IOS图片的原生(Graphics)详解及实例

2019年07月24日  | 移动技术网IT编程  | 我要评论

忘词帝文摘,纵横道,郑松美

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.
}

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网