我正在尝试制作一个测试应用程序,当用户单击一个按钮时,文本会切换到其他内容,如果再次单击它,它会返回,但我也希望能够添加一个用户输入他/她的名字是这样说的,隐藏的信息是:或者其他什么......
我的代码是:
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//button.backgroundColor = [UIColor redColor];
button.titleLabel.textColor=[UIColor blackColor];
button.frame = CGRectMake(25, 100, 275, 60);
[button setTitle:@"Press this button to reveal the text!" forState:UIControlStateNormal];
[button addTarget:self action:@selector(button_method:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)button_method:(UIButton *)button {
NSString *test = @"I am learning Objective-C for the very first time! Also, this is my first ever variable!";
// handle button press
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25, 25, 275, 60)];
label.text = test;
label.numberOfLines = 0;
label.lineBreakMode = UILineBreakModeWordWrap;
//label.lineBreakMode = NSLineBreakByWordWrapping; //iOS 6 only
[self.view addSubview:label];
[button setTitle:@"You have pressed the button!" forState:UIControlStateNormal];
[button addTarget:self action:@selector(change_again:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)change_again:(UIButton *)button {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25, 25, 275, 60)];
label.text = @"You have found the next piece of text!";
label.numberOfLines = 0;
label.lineBreakMode = UILineBreakModeWordWrap;
//label.lineBreakMode = NSLineBreakByWordWrapping; //iOS 6 only
[self.view addSubview:label];
[button setTitle:@"Keep pressing!" forState:UIControlStateNormal];
[button addTarget:self action:@selector(button_method:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
我希望这不会被认为过于本地化!
穆克曼
PS:一个附带问题,我将如何创建一个字符串,例如NSString *var4 = var.var2.var3;
什么是加入字符?在 JavaScript 中是+
在 PHP 中.