iPhone Private Buttons

    

保存显示的私有button到指定文件夹

  Class theClass = NSClassFromString(@"UIGlassButton");

    UIButton *theButton = [[[theClass alloc] initWithFrame:CGRectMake(10, 10, 240, 44)] autorelease];

    [theButton setValue:[UIColor colorWithHue:0.267 saturation:1.000 brightness:0.667 alpha:1.000] forKey:@"tintColor"];


    [self.view addSubview:theButton];


    NSString *filePath = [NSString stringWithFormat:@"%@/Documents/glass-button.png", NSHomeDirectory()];

  UIGraphicsBeginImageContext(theButton.frame.size);    

    CGContextRef theContext = UIGraphicsGetCurrentContext();

    [theButton.layer renderInContext:theContext];

    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

    NSData *theData = UIImagePNGRepresentation(theImage);

    [theData writeToFile:filePath atomically:NO];

    UIGraphicsEndImageContext();

posted @ 2011-09-26 17:46  真相天下  阅读(106)  评论(0)    收藏  举报