- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当从上一个 View 中按下“下一步”按钮时,我试图在新 View 上设置 UIButton 的文本。我已经正确设置了 IBOutlet,并且我已经到处寻找答案,但它根本不起作用。
这是我正在尝试做的事情的示例:
- (IBAction)computeQuiz:(id)sender
{
[fiveFootUniversalResults setTitle:@"Test" forState:UIControlStateNormal];
}
- (IBAction)jumpT10ResultsView:(id)sender
{
NSString *nibFileToLoad = @"JumpT10Results";
UIDevice *device = [UIDevice currentDevice];
if([device userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
nibFileToLoad = [nibFileToLoad stringByAppendingString:@"-iPad"];
}
JumpmasterPathfinderViewController *nextView = [[JumpmasterPathfinderViewController alloc] initWithNibName:nibFileToLoad bundle:nil];
// Modal view controller
nextView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:nextView animated:YES];
[nextView release];
[scrollView setContentSize:CGSizeMake(imageViewWidth, imageViewHeight + 44.0)];
}
这些操作都连接到上一个 View 上的按钮。 View 加载正常,一切正常,唯一的问题是按钮上的文本不会改变。我 100% 确定我已正确设置 IBOutlets,我只是不知道我做错了什么。有什么想法吗?
最佳答案
它不起作用,因为 IB 设置了 attributedTitle
而不是 title
。
试试这个:
NSAttributedString *attributedTitle = [self.myButton attributedTitleForState:UIControlStateNormal];
NSMutableAttributedString *mas = [[NSMutableAttributedString alloc] initWithAttributedString:attributedTitle];
[mas.mutableString setString:@"New Text"];
[self.myButton setAttributedTitle:mas forState:UIControlStateNormal];
或者,另一种选择:
[self.myButton setAttributedTitle:nil forState:UIControlStateNormal];
[self.myButton setTitle:@"New Text" forState:UIControlStateNormal];
(第二个选项不会保留您的格式。)
关于iphone - UIButton setTitle forState 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7986090/
我正在尝试为 UIButton 设置图像。 我不知道 setBackgroundImage:Forstate 和 setImage:Forstate 之间的区别: 谁能帮帮我? 谢谢并致以最诚挚的问候
您好,我的代码第 58 行出现错误。我收到错误: Syntax error, insert "; ; ) Statement" to complete For Statement 当我尝试编译时。我正
我有一个我无法解决的小问题。我有大约 16 个按钮,它们作为 socket 集合连接到我的 Controller 。它们还有一个操作方法,可以使按钮的状态从默认状态更改为选中状态。我试图将所有按钮的图
当从上一个 View 中按下“下一步”按钮时,我试图在新 View 上设置 UIButton 的文本。我已经正确设置了 IBOutlet,并且我已经到处寻找答案,但它根本不起作用。 这是我正在尝试做的
我正在尝试为所有UIBarButtonItem设置标题颜色 当我使用时: [[UIBarButtonItem appearance] setTitleColor:normalTitleColor f
我有一个从 IB 实例化的 View Controller 。它包含一个 UIButton,其操作创建一个 UIPopoverController,其委托(delegate)通过以下方式更新 UIBu
我有一个带有 CustomCollectionViewCell 类的 UICollectionView。在单元格内,我有一个用 Storyboard设置的按钮。我希望按钮在点击时改变其颜色,但我总是得
我正在使用 setBackgroundImage:forState:像这样为各种状态的背景图像着色: [myButton setBackgroundImage:genericImage forStat
为什么下面的代码可以工作... [signInBtn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted]; [
iOS中UIBarItem中的setTitleTextAttributes:forState:如何使用? 你如何设置NSDictionary?无法使其工作,文档对此也不是很清楚。 来自文档: setT
我有一个应用程序,可以从相机捕获图像并将其设置为按钮。 因此,从相机捕获图像并点击使用按钮后,我的应用程序因 [NSCFType setImage:forstate] 无法识别的实例而崩溃 - (v
我有一个 tableview,它运行一些代码在后台线程中从 NSData 获取 UIImage,然后在前台它调用 [button setImage:image forState:UIControlSt
我有一个我想要转换的代码模块 for (var key in foo){} 进入 for (var keys = 0; key { var prop = p.node.left.de
我正在尝试使用 Interface Builder 中的实时呈现为 UIButtons 实现一个可本地化的类。这是我到目前为止的代码: @IBDesignable class TIFLocalizab
我正在尝试在自定义 UIButton 上为我的标题添加下划线,但是按照找到的示例 here ,我无法让它显示在屏幕上。 这是我尝试使用的代码: NSMutableAttributedString *c
我正在尝试动态更新 UIButton 的 IBOutletCollection 的标题。我希望标题设置为 选中时字母“S”和 禁用和选中时的文本“D|S”。 它不工作,所以我打印了 titleForS
我只是尝试使用 myBtn.imageview.image = newimg; 为我的 UIButton 设置一个新图像(UIImage 对象),然后我发现它不起作用。 之后我得到了正确的解决方案,使
我总是这样设置 UIButton 的标题 aButton.setTitle(title, for: .normal) 然而,最近我看到了这个 aButton.setTitle(title, for:
预期的行为是在单击播放操作时更改图像(从播放到暂停以及从暂停到播放)。这在版本 4.x 中按预期工作。在版本 3.2 中,setImage 不起作用,这意味着 setImage 不设置图像。在 3.2
这个问题在这里已经有了答案: How to stop unwanted UIButton animation on title change? (24 个答案) 关闭 6 年前。 我正在使用 NST
我是一名优秀的程序员,十分优秀!