小编Mar*_*kus的帖子

以编程方式更改UIButton的属性标题

我想以编程方式更改UIButton具有属性标题的标题.该按钮在IB中创建.我不想仅仅改变标题/文本的属性.

我已经尝试了下面的代码,但无法找到更改标题的方法NSAttributedString.

NSAttributedString *attributedString = [self.deleteButton attributedTitleForState:UIControlStateNormal];

// How can I change title of attributedString without changing the attributes?

[self.deleteButton setAttributedTitle:attributedString forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)

谢谢!

uibutton ios

13
推荐指数
2
解决办法
1万
查看次数

如何知道视图控制器是否将呈现为弹出框或模态框?

在呈现视图控制器之前,我将modalPresentationStyle属性设置为UIModalPresentationPopover。当在具有常规水平尺寸类别(横向的 iPad 和 iPhone 6+)的设备上运行时,这会将视图控制器呈现为弹出窗口,并在其他设备上呈现为模式/全屏。还可以通过覆盖来覆盖此行为adaptivePresentationStyleForPresentationController,以便视图控制器在所有设备上显示为弹出窗口。

我想知道在呈现视图控制器之后是否有可能知道它是否作为弹出框呈现?仅查看尺寸类是不行的,因为视图控制器可能会覆盖adaptivePresentationStyleForPresentationController.

明显的答案是,作为程序员,我应该知道我是否重写adaptivePresentationStyleForPresentationController,但我想编写一个函数,可以通过传入视图控制器或(或UIPopoverPresentationController任何其他对象)在运行时为任何视图控制器确定这一点需要)作为参数。

下面是一些展示视图控制器的代码:

navigationController = (UINavigationController *)[MVSStore sharedInstance].addViewController;
navigationController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:navigationController animated:YES completion:^{}];

UIPopoverPresentationController *popoverController = navigationController.popoverPresentationController;
popoverController.sourceView = self.view;
popoverController.sourceRect = CGRectMake(20, 20, 20, 20); // Just a dummy
popoverController.permittedArrowDirections = UIPopoverArrowDirectionAny;
Run Code Online (Sandbox Code Playgroud)

这是当前的代码,用于检测视图控制器是否显示为弹出窗口。但如上所述,它只是查看尺寸类别,并不适用于所有情况。

+ (BOOL)willPresentTruePopover:(id<UITraitEnvironment>)vc {
    return ([vc traitCollection].horizontalSizeClass == UIUserInterfaceSizeClassRegular);
}
Run Code Online (Sandbox Code Playgroud)

UIViewController我无法在或(或其他任何地方)中找到任何UIPopoverPresentationController可以立即为我提供此信息的属性或函数,但也许我遗漏了一些东西?

iphone uikit popover ipad ios

6
推荐指数
1
解决办法
2198
查看次数

是否有一种简单而美观的方式将列表中的项目转换为不同类型?

我从REST API获得了一个字符串列表.我从文档中知道索引0和2处的项是整数,而1和3处的项是浮点数.

要使用我需要将其转换为正确类型的数据进行任何类型的计算.虽然每次使用它时都可以转换值,但我宁愿在开始计算之前将列表转换为正确的类型以保持方程更清晰.下面的代码工作,但非常难看:

rest_response = ['23', '1.45', '1', '1.54']
first_int = int(rest_response[0])
first_float = float(rest_response[1])
second_int = int(rest_response[2])
second_float = float(rest_response[3])
Run Code Online (Sandbox Code Playgroud)

由于我在这个特定的例子中使用整数和浮点数,一种可能的解决方案是将每个项目转换为浮点数.float_response = map(float, rest_response).然后我可以简单地解压缩列表以在方程中相应地命名值.

first_int, first_float, second_int, second_float = float_response
Run Code Online (Sandbox Code Playgroud)

这是我目前的解决方案(但有更好的名字),但在找出一个我感到好奇,如果有任何好的pythonic解决这种问题?

python

5
推荐指数
2
解决办法
139
查看次数

标签 统计

ios ×2

ipad ×1

iphone ×1

popover ×1

python ×1

uibutton ×1

uikit ×1