作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
之前有人问过(使用文本字段,我问的是如何包含一个字符而不是一个小图标),是的,我已经尝试过使用这个 SetLeftView
来放置一个美元符号 ' $' 或我想要在文本字段旁边的任何字符。
但是,我不想要一个文本字段,而是一个标签,当我应用相同的代码来执行我想要的操作时,它会返回一个错误,我的意思是 Xcode 无法构建代码。
这是我的代码:
// We add a label to the top that will display the results
self.resultLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 80, TEXTAREA_WIDTH, TEXTAREA_HEIGHT)];
[resultLabel setBackgroundColor:[UIColor clearColor]];
[resultLabel setText:@"01234"];
[resultLabel setFont:[UIFont fontWithName:@"AppleGothic" size:30.0f]];
resultLabel.textColor = RGB(255,255,255);
resultLabel.textAlignment = NSTextAlignmentCenter;
// Add it to the view
[self.view addSubview:resultLabel];
UILabel *dollarSignLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 80, 25, 40)];
dollarSignLabel.text = @"$";
dollarSignLabel.textColor = RGB(255,255,255);
[dollarSignLabel setFont:[UIFont fontWithName:@"AppleGothic" size:30.0f]];
[resultLabel setLeftView:dollarSignLabel];
[resultLabel setLeftViewMode:UITextFieldViewModeAlways];
Error: No visible @interface for 'UILabel' declares the selector 'setLeftView'. Same error in the line of setLeftViewMode.
同样,如果我使用文本字段,这会起作用。
我的工作代码(使用文本框)
// adding a textField for input
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(viewHalf-30, 100, 200, 40)];
[myTextField setBackgroundColor:[UIColor clearColor]];
[myTextField setText:@"0"];
[myTextField setFont:[UIFont fontWithName:@"AppleGothic" size:30.0f]];
myTextField.textColor = RGB(255,255,255);
[[self view] addSubview:myTextField];
UILabel *dollarSignLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 25, 40)];
dollarSignLabel.text = @"$";
dollarSignLabel.textColor = RGB(255,255,255);
[dollarSignLabel setFont:[UIFont fontWithName:@"AppleGothic" size:30.0f]];
[myTextField setLeftView:dollarSignLabel];
[myTextField setLeftViewMode:UITextFieldViewModeAlways];
最佳答案
你不能应用它的原因是因为 UILabel 没有像 UITextField 那样的名为 setLeftView 的方法。
你可以做的是:
关于ios - 标签 Objective-C 中的 SetLeftView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32432113/
之前有人问过(使用文本字段,我问的是如何包含一个字符而不是一个小图标),是的,我已经尝试过使用这个 SetLeftView 来放置一个美元符号 ' $' 或我想要在文本字段旁边的任何字符。 但是,我不
我想在我的文本字段中有一个图标,并且我正在使用 setLeftView 属性。我现在的代码是 UIView *leftView = [[UIView alloc] initWithFrame:
我是一名优秀的程序员,十分优秀!