How can I change the image displayed in an UIImageView programmatically?
有url的image
- (void)viewDidLoad
{
[super viewDidLoad];
[outputImage setImage:[UIImage imageNamed:[NSString stringWithFormat:@"http://xxx/images/location/location1.png"]]];
}
url的image 檔名需可變動.h
@interface TabLocationView : UIViewController
{
NSInteger selectedIndex;
IBOutlet UIImageView *outputImage;
}
@property (nonatomic) NSInteger selectedIndex;
.m
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://xxx/images/location%d.png",selectedIndex+1]]]];
NSLog(@"%d",selectedIndex+1);
[outputImage setImage:image];
}

沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。