iOS5自定义控件-创新互联

创新互联建站长期为1000多家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为东兴企业提供专业的成都做网站、成都网站建设,东兴网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。>// 在iOS 5下自定义控件的外观- (void)customizeAppearance { // UINavigationBar UIImage *gradientImage44 = [[UIImage imageNamed:@"surf_gradient_textured_44"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; UIImage*gradientImage32 = [[UIImage imageNamed:@"surf_gradient_textured_32"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; [[UINavigationBar appearance] setBackgroundImage:gradientImage44 forBarMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setBackgroundImage:gradientImage32 forBarMetrics:UIBarMetricsLandscapePhone]; [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0], UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"Arial-Bold" size:0.0], UITextAttributeFont,nil]];

  [[vcnavigationItem]setTitleView:[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"title"]]];
 iOS5自定义控件
// UIBarButtonItem    UIImage *button30 = [[UIImage imageNamed:@"button_textured_30"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
    UIImage*button24 = [[UIImage imageNamed:@"button_textured_24"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];    
    [[UIBarButtonItem appearance]  setBackgroundImage:button30  forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UIBarButtonItem appearance]  setBackgroundImage:button24  forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
    [[UIBarButtonItem appearance]  setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
    [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0], UITextAttributeTextColor,
    [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0], UITextAttributeTextShadowColor,
    [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
    [UIFont fontWithName:@"AmericanTypewriter" size:0.0], UITextAttributeFont, nil]
     forState:UIControlStateNormal];

// Back Button    UIImage *buttonBack30 = [[UIImage imageNamed:@"button_back_textured_30"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)];
    UIImage*buttonBack24 = [[UIImage imageNamed:@"button_back_textured_24"]  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 5)];
    [[UIBarButtonItem appearance]  setBackButtonBackgroundImage:buttonBack30  forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UIBarButtonItem appearance]  setBackButtonBackgroundImage:buttonBack24  forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
  
// UITabBar    UIImage *tabBackground = [[UIImageimageNamed:@"tab_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [[UITabBar appearance] setBackgroundImage:tabBackground];
    [[UITabBar appearance] setSelectionIndicatorImage: [UIImage imageNamed:@"tab_select_indicator"]];   

// UISlider    UIImage *minImage = [[UIImage imageNamed:@"slider_minimum.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
    UIImage*maxImage = [[UIImage imageNamed:@"slider_maximum.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
    UIImage*thumbImage = [UIImage imageNamed:@"thumb.png"];

    [[UISlide rappearance] setMaximumTrackImage:maxImage forState:UIControlStateNormal];
    [[UISlider appearance] setMinimumTrackImage:minImage forState:UIControlStateNormal];
    [[UISlider appearance] setThumbImage:thumbImage forState:UIControlStateNormal];


// UISegmentedControl    UIImage *segmentSelected = [[UIImage imageNamed:@"segcontrol_sel.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];
    UIImage*segmentUnselected = [[UIImage imageNamed:@"segcontrol_uns.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];
    UIImage*segmentSelectedUnselected = [UIImage imageNamed:@"segcontrol_sel-uns.png"];
    UIImage*segUnselectedSelected = [UIImage imageNamed:@"segcontrol_uns-sel.png"];
    UIImage*segmentUnselectedUnselected = [UIImage imageNamed:@"segcontrol_uns-uns.png"];

    [[UISegmentedControl appearance] setBackgroundImage:segmentUnselected forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UISegmentedControl appearance] setBackgroundImage:segmentSelected forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
    [[UISegmentedControl appearance] setDividerImage:segmentUnselectedUnselected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UISegmentedControl appearance] setDividerImage:segmentSelectedUnselected forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UISegmentedControl appearance] setDividerImage:segUnselectedSelected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
}

// UISwitch[rentSwitch setOnTintColor:[UIColor colorWithRed:0 green:175.0/255.0 blue:176.0/255.0 alpha:1.0]];


// UITextField- (void)drawRect:(CGRect)rect
{
    UIImage*textFieldBackground = [[UIImage imageNamed:@"text_field_teal.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15.0, 5.0, 15.0, 5.0)];
    [textFieldBackground drawInRect:[self bounds]];
}

本文标题:iOS5自定义控件-创新互联
网页链接:http://myzitong.com/article/ceojdp.html