-1

我在 iphone 应用程序中遇到了意外的问题。无论出于何种原因,我编译这个,我得到一个 SIGABRT 错误。它发生在:

    textFieldRounded=[[UITextField alloc]initWithframe: CGRectMake(20,50,280,31)];
    textFieldRounded.borderStyle=UITextBorderStyleRoundedRect;
    textFieldRounded.textColor=[UIColor blackColor];
    textFieldRounded.font=[UIFont systemFontOfSize:17.0];
    textFieldRounded.placeholder=@"enter your name";
    textFieldRounded.backgroundColor=[UIColor whiteColor];
    textFieldRounded.autocorrectionType=UITextAutocorrectionTypeNo;
    textFieldRounded.backgroundColor=[UIColor clearColor];
    textFieldRounded.keyboardType=UIKeyboardTypeDefault;
    textFieldRounded.returnKeyType=UIReturnKeyDone;
    textFieldRounded.clearButtonMode=UITextFieldViewModeWhileEditing;
    [self.view addSubView:textFieldRounded];
    textFieldRounded.delegate=self;    
    UIButton *button =[UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self action:@selector(buttonPressed:)
     forControlEvents:UIControlEventTouchDown];
    [button setTitle:@"Button" forstate:UIControlStateNormal];
    button.frame = CGRectMake(20,108,97,37);
    [self.view addSubview:button];
    label= [[UILabel alloc] initWithFrame:CGRectMake(40,243,240,21)];
    label.backgroundColor=[UIColor clearColor];
    label.textAlignment,UITextAlignmentCenter;
    label.text=@"Label";
    [self.view addSubview:label];    
    CGRect myImageRect = CGRectMake(40.0f,190.0f,240.0f,128.0f);
    image= [[UIImageView alloc] initWithFrame:myImageRect];
    [image setImage:[UIImage imageNamed:@"Default@2x.png"]];
    image.backgroundColor=[UIColor clearColor];
    image.opaque =YES;
    image.alpha=0;
    [self.view addSubview:image];
    [image release];
}
4

1 回答 1

1

你可以创建UITextFieldUIButton或者UILabel像下面的代码: -

UITextField

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = @"enter text";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;    
textField.delegate = self;
[self.view addSubview:textField];
[textField release];

用户界面按钮

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"UIButton" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];
[button release];

UIL标签

UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 240, 300, 30)];

[self.view addSubview:headingLabel];

// 可选的

headingLabel.text = @"WELCOME";
headingLabel.textColor = [UIColor orangeColor];
headingLabel.textAlignment = UITextAlignmentCenter;
headingLabel.tag = 10;
headingLabel.backgroundColor = [UIColor clearColor];
headingLabel.font = [UIFont fontWithName:@"MarkerFelt-Thin" size:14.0];
headingLabel.hidden = NO;
headingLabel.highlighted = YES;
headingLabel.highlightedTextColor = [UIColor blueColor];
headingLabel.lineBreakMode = YES;
headingLabel.numberOfLines = 0;

UIImageView

UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
myImage.image = [UIImage imageNamed:@"myImage.png"];
[self.view addSubview:myImage];
[mymyImage release];

希望它可以帮助你

于 2013-01-10T09:24:59.760 回答