First, the preamble procedure
Create a new project and implement the following lines of code in the main controller file to easily tile the picture in the view.
1 #import "YYViewController.h"2 3 @interfaceYyviewcontroller ()4 5 @end6 7 @implementationYyviewcontroller8 9- (void) ViewdidloadTen { One [Super Viewdidload]; A -UIImage *image = [UIImage imagenamed:@"Me"]; -Uicolor *color =[Uicolor colorwithpatternimage:image]; theSelf.view.backgroundcolor=color; - } - - @end
Effect:
Second, the realization of stationery stripe effect
Use the above feature to make a stationery effect. There are no split lines on the default view, there are two ways to add split lines to the View: (1) Let the artist make a picture that is used to make the background, and set the picture as the background. Cons: The length of the letter is uncertain, so the length of the background image is difficult to determine. (2) Create a color with a small picture and tile to achieve the background effect. Step one: Create a small image to be tiled later. Draw a rectangle. Draw lines. Step two: Remove the picture from the context to set the background. Dark piece? (Other places are transparent, the controller's color, if not set then the default is black) implementation code:
1 //2 //YYVIEWCONTROLLER.M3 //01-Stationery Stripe4 //5 //Created by Hole Medical has on 14-6-11.6 //Copyright (c) 2014 itcast. All rights reserved.7 //8 9 #import "YYViewController.h"Ten One @interfaceYyviewcontroller () A - @end - the @implementationYyviewcontroller - -- (void) Viewdidload - { + [Super Viewdidload]; - + A //1. Create a small picture for tiling later atCgsize size = Cgsizemake (Self.view.frame.size.width, *); - //Open Picture Context -Uigraphicsbeginimagecontextwithoptions (Size, NO,0); - - //2. Draw a rectangle -Cgcontextref CTX =Uigraphicsgetcurrentcontext (); inCGFloat height = *; -Cgcontextaddrect (CTX, CGRectMake (0,0, self.view.frame.size.width, height)); to[[Uicolor Whitecolor]Set]; + Cgcontextfillpath (CTX); - the //3. Draw Lines *CGFloat linewidth =2; $CGFloat Liney = height-linewidth;Panax NotoginsengCGFloat LineX =0; - Cgcontextmovetopoint (CTX, LineX, Liney); theCgcontextaddlinetopoint (ctx,self.view.frame.size.width, Liney); +[[Uicolor Blackcolor]Set]; A Cgcontextstrokepath (CTX); the + //Get Picture Context -UIImage *image =Uigraphicsgetimagefromcurrentimagecontext (); $Uicolor *color =[Uicolor colorwithpatternimage:image]; $Self.view.backgroundcolor=color; - } - the @end
Effect:
Third, the application scenario
Complete a humble ebook reader
Code:
1 //2 //YYVIEWCONTROLLER.M3 //01-Stationery Stripe4 //5 //Created by Apple on 14-6-11.6 //Copyright (c) 2014 itcast. All rights reserved.7 //8 9 #import "YYViewController.h"Ten One @interfaceYyviewcontroller () A -@property (Weak, nonatomic) iboutlet Uitextview *TextView; --(Ibaction) Perbtnclick: (UIButton *) sender; the-(Ibaction) Nextbtnclick: (UIButton *) sender; -@property (nonatomic,assign)intindex; - @end - + @implementationYyviewcontroller - +- (void) Viewdidload A { at [Super Viewdidload]; - - - //1. Create a small picture for tiling later -Cgsize size = Cgsizemake (Self.view.frame.size.width, -); -Uigraphicsbeginimagecontextwithoptions (Size, NO,0); in - //2. Draw a rectangle toCgcontextref CTX =Uigraphicsgetcurrentcontext (); +CGFloat height = -; -Cgcontextaddrect (CTX, CGRectMake (0,0, self.view.frame.size.width, height)); the[[Uicolor Browncolor]Set]; * Cgcontextfillpath (CTX); $ Panax Notoginseng //3. Draw Lines - theCGFloat linewidth =2; +CGFloat Liney = height-linewidth; ACGFloat LineX =0; the Cgcontextmovetopoint (CTX, LineX, Liney); +Cgcontextaddlinetopoint (CTX, the, Liney); -[[Uicolor Blackcolor]Set]; $ Cgcontextstrokepath (CTX); $ - -UIImage *image =Uigraphicsgetimagefromcurrentimagecontext (); theUicolor *color =[Uicolor colorwithpatternimage:image]; - // self.view.backgroundColor = color;WuyiSelf.textview.backgroundColor =color; the } - Wu-(Ibaction) Perbtnclick: (UIButton *) Sender { -self.index--; AboutSelf.textview.text = [NSString stringWithFormat:@"Page%d", Self.index]; $Catransition *ca =[[Catransition alloc] init]; -Ca.type =@"Pagecurl"; - - [Self.textview.layer ADDANIMATION:CA forkey:nil]; A + } the --(Ibaction) Nextbtnclick: (UIButton *) Sender { $self.index++; theSelf.textview.text=[nsstring stringWithFormat:@"Page%d", Self.index]; theCatransition *ca =[[Catransition alloc] init]; theCa.type =@"Pagecurl"; the - [Self.textview.layer ADDANIMATION:CA forkey:nil]; in } the @end
The interface layout in storyboard
The simple effect of the implementation:
iOS Development UI Chapter-quartz2d use (Stationery stripe)