天天看點

uialertview 圖檔_UIAlertView添加圖檔并且改變按鈕的位置

#import "pwdAlertView.h"

@implementation pwdAlertView

@synthesize passwordText;

-

(id)initWithFrame:(CGRect)frame

{

if (self = [super initWithFrame:frame]) {

isMatch = NO;

//user pass_word

pass_word = [[UILabel alloc] initWithFrame:CGRectZero];

[pass_word setBackgroundColor:[UIColor clearColor]];

pass_word.lineBreakMode = UILineBreakModeWordWrap;

//pass_word.numberOfLines = 1

[pass_word setTextColor:[UIColor whiteColor]];

[pass_word setFont:[UIFont systemFontOfSize:15.0]];

pass_word.text = @"密碼";

passwordText = [[UITextField alloc] initWithFrame:CGRectZero];

[passwordText setSecureTextEntry:YES];

[passwordText setBackgroundColor:[UIColor clearColor]];

[passwordText setBorderStyle:UITextBorderStyleBezel];

passwordText.backgroundColor = [UIColor whiteColor];

passwordText.placeholder = @"密碼";

[passwordText becomeFirstResponder];

passwordText.clearButtonMode = UITextFieldViewModeWhileEditing;

[self

addSubview:pass_word];

[self

addSubview:passwordText];

}

return self;

}

-

(void)setFrame:(CGRect)rect

{

[super

setFrame:CGRectMake((320-rect.size.width)/2, 130,

rect.size.width, 150)];

//self.center = CGPointMake(320/2, 480/2);

}

-

(void)layoutSubviews {

CGFloat buttonTop;

for (UIView *view in self.subviews) {

if ([[[view class] description]

isEqualToString:@"UIThreePartButton"]) {

view.frame = CGRectMake(view.frame.origin.x,

self.bounds.size.height -

view.frame.size.height - 15,

view.frame.size.width,

view.frame.size.height);

buttonTop = view.frame.origin.y;

}

}

buttonTop -= 40;

pass_word.frame = CGRectMake(12, buttonTop, 40, 30);

passwordText.frame =

CGRectMake(pass_word.frame.origin.x+pass_word.frame.size.width,

pass_word.frame.origin.y,

200,

pass_word.frame.size.height);

}

-

(void)setPassword:(NSString

*)_pwd {

if (pwd)

[pwd release];

pwd

= [_pwd retain];

}

-

(BOOL)match {

if (!passwordText || !pwd)

{

isMatch = NO;

return NO;

}

if ([pwd

isEqualToString:passwordText.text]) {

isMatch = YES;

return YES;

}

isMatch = NO;

return NO;

}

-

(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex

animated:(BOOL)animated {

if (buttonIndex == 1 &&

!isMatch) {

return;

}

[passwordText resignFirstResponder];

[super

dismissWithClickedButtonIndex:buttonIndex animated:animated];

}

-

(void)dealloc {

[pass_word release];

[passwordText release];

[pwd release];

[super dealloc];

}

@end