标签:
效果如下:
ViewController.h
1 #import <UIKit/UIKit.h> 2 3 @interface ViewController : UIViewController 4 @property (strong, nonatomic) IBOutlet UISegmentedControl *colorChoice; 5 @property (strong, nonatomic) IBOutlet UILabel *chosenColor; 6 @property (strong, nonatomic) IBOutlet UIWebView *flowerView; 7 8 @end
ViewController.m
1 #import "ViewController.h" 2 3 @interface ViewController () 4 @end 5 6 @implementation ViewController 7 8 - (IBAction)getFlower:(id)sender { 9 NSString *colorVal; 10 NSInteger colorIndex = self.colorChoice.selectedSegmentIndex; 11 switch (colorIndex) { 12 case 0: 13 colorVal = @"red"; 14 break; 15 case 1: 16 colorVal = @"blue"; 17 break; 18 case 2: 19 colorVal = @"yellow"; 20 break; 21 case 3: 22 colorVal = @"green"; 23 break; 24 default: 25 break; 26 } 27 self.chosenColor.text = colorVal; 28 NSString *outputHTML = [[NSString alloc] initWithFormat:@"<body style=‘margin: 0px; padding: 0px‘><img style=‘width:560px, height:420px‘ src=‘http://www.floraphotographs.com/showrandom.php?color=%@‘></body>", colorVal]; 29 [self.flowerView loadHTMLString:outputHTML baseURL:nil]; 30 } 31 32 - (void)viewDidLoad { 33 [super viewDidLoad]; 34 // Do any additional setup after loading the view, typically from a nib. 35 } 36 37 - (void)didReceiveMemoryWarning { 38 [super didReceiveMemoryWarning]; 39 // Dispose of any resources that can be recreated. 40 } 41 42 @end
标签:
原文地址:http://www.cnblogs.com/huangjianwu/p/4575918.html