IOS controls with multiple options for animation (1)

Source: Internet
Author: User

IOS controls with multiple options for animation (1)

First:



This program has two levels. One is the bar with UITextField on the top, and the other is the view selected from the drop-down list. The selected view has four custom uiviews.

We first define a UIViewController named MyViewController, and then the bar on the top is TopBarView. The view selected from the drop-down list is TypeSelectView. A custom view like UIButton is called TypeView. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + expires/expires + 0 vLOqs/CwK2/expires + PGJyPgo8L3A + CjxwPs/expires + CjxwPjxwcmUgY2xhc3M9 "brush: java; "># define TypeView_Width 76 # define TypeView_Height 76 @ class TypeSelectView; @ interface TypeView: UIView @ property (nonatomic, assign) int typeId; @ property (nonatomic, assign) BOOL bSelected; @ property (nonatomic, strong) TypeSelectView * typesView; @ end
Touch event:

-(Void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {if (! _ BSelected) {// if the selected item is not selected, We need to cancel the selected status of the selected item in TypeSelectView if (_ typesView. curSelectedView) {_ typesView. curSelectedView. bSelected = NO; [_ typesView. curSelectedView setNeedsDisplay];} _ bSelected = YES; _ typesView. curSelectedView = self; [self setNeedsDisplay];}

Then there is draw:

-(Void) drawRect :( CGRect) rect {CGContextRef context = UIGraphicsGetCurrentContext (); Digest (context, [CCommon RGBColorFromHexString: @ "# c5c4cc" alpha: 1.0f]. CGColor); CGFontRef contextFont = CGFontCreateWithFontName (CFStringRef) [UIFont systemFontOfSize: 14]. fontName); CGContextSetFont (context, contextFont); CFRelease (contextFont); CGContextSetFontSize (context, 14.0); if (_ bSelected) {// display the select background UIImage * bgImage = [UIImage imageNamed: @ "change_icon_touch_bg.png"]; CGRect bgRc = rect; bgRc. origin. x = (bgRc. size. width-bgImage. size. width)/2 + 1.0f; // locate the x coordinate bgRc in the upper left corner of the background image. origin. y = (bgRc. size. height-bgImage. size. height)/2; // locate the y coordinate bgRc in the upper left corner of the background image. size = bgImage. size; // the size of the background image given by the ui is the size of the control [bgImage drawInRect: bgRc]; CGContextSetFillColorWithColor (context, [CCommon RGBColorFromHexString: @ "#58 baff" alpha: 1.0f]. CGColor); // intermediate fill color} // draw image NSString * imageName = [NSString string]; NSString * text = [NSString string]; imageName = @ "mbWWW.png "; if (_ typeId = 0) {text = @ "web";} else if (_ typeId = 1) {text = @ "weibo ";} else if (_ typeId = 2) {text = @ "sina";} else if (_ typeId = 3) {text = @ "sohu ";} if (_ bSelected) {imageName = [imageName stringByReplacingOccurrencesOfString :@". png "withString: @" _touch.png "];} // name of the src image in the view given by imageName. In either or both states, UIImage * typeImage = [UIImage imageNamed: imageName]; CGRect rc = rect; rc. origin. x = (rc. size. width-typeImage. size. width)/2; rc. origin. y = 10; rc. size = typeImage. size; [typeImage drawInRect: rc]; // draw text: CGPoint textPt = CGPointMake (rc. origin. x, rc. origin. y + rc. size. height + 10); [text drawAtPoint: textPt withFont: [UIFont systemFontOfSize: 14.0f];}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.