在我的應用程序中,我試圖在 它被選中,填充或留空時,在我的輸入字段中更改圖標(圖像視圖)的阿爾法。更改圖片阿爾法
我已經寫了這段代碼,但沒有任何事情發生,我確信我寫了圖像名稱,因爲它們在我的圖像目錄中命名。
示例代碼;
- (IBAction)passwordInputTab:(id)sender {
UIImageView *imageLockIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lock-icon.png"]];
imageLockIcon.alpha = 1;
//self.txtPassword.alpha = 1;
if ([[self.txtUsername text] isEqualToString:@""]) {
//self.txtUsername.alpha = 0.5;
UIImageView *imageUserIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user-icon.png"]];
imageUserIcon.alpha = 0.5;
}
}
- (IBAction)usernameInputTab:(id)sender {
UIImageView *imageUserIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user-icon.png"]];
imageUserIcon.alpha = 1;
NSLog(@"==> %@", imageUserIcon);
//userIcon.alpha = 0.1;
if ([[self.txtPassword text] isEqualToString:@""]) {
UIImageView *imageLockIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lock-icon.png"]];
imageLockIcon.alpha = 0.5;
NSLog(@"==> %@", imageLockIcon);
//self.txtPassword.alpha = 0.5;
}
}
Log;
2014-09-18 21:47:10.882 ...[1280:60b] ==> <UIImageView: 0x14e8dd90; frame = (0 0; 17 16); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x14e8de10>>
2014-09-18 21:47:10.884 ...[1280:60b] ==> <UIImageView: 0x14d66770; frame = (0 0; 12 16); alpha = 0.5; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x14da43d0>>
感謝Marck!由IBOUtlet解決! :) – directory 2014-09-18 21:22:25