我在渲染具有自定义 uiappearance 集的滑块的视图控制器的图像时遇到问题。图像渲染良好,但是图像中的滑块只有默认外观。如果我转到该视图控制器 (vc2),则 uiappearance 将设置为自定义外观。任何想法如何使用自定义滑块外观呈现图像?
我在第一个视图控制器上有一个 UIImageView。在第二个视图控制器上,我有一个滑块。
视图控制器.m
ViewController *vc2 = [[ViewController alloc]init];
vc2 = [self.storyboard instantiateViewControllerWithIdentifier:@"vc2"];
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size,NO,0.0);
[vc2.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[_image setImage:viewImage];
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self customizeAppearance];
// Override point for customization after application launch.
return YES;
}
- (void) customizeAppearance; {
UIImage *minImage = [[UIImage imageNamed:@"slider_minimum.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 0)];
UIImage *maxImage = [[UIImage imageNamed:@"slider_maximum.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 13)];
UIImage *thumbImage = [UIImage imageNamed:@"slider_thumb.png"];
[[UISlider appearance] setMaximumTrackImage:maxImage
forState:UIControlStateNormal];
[[UISlider appearance] setMinimumTrackImage:minImage
forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:thumbImage
forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:thumbImage
forState:UIControlStateHighlighted];
}