我想复制UITextField占位符字段的默认颜色.从文档:
占位符字符串使用70%灰色绘制.
从python文档docs.python.org/tutorial/introduction.html#strings:
切片索引具有有用的默认值; 省略的第一个索引默认为零,省略的第二个索引默认为要切片的字符串的大小.
对于标准情况,这很有意义:
>>> s = 'mystring'
>>> s[1:]
'ystring'
>>> s[:3]
'mys'
>>> s[:-2]
'mystri'
>>> s[-1:]
'g'
>>>
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.但是,使用负步长值似乎表明默认值略有不同:
>>> s[:3:-1]
'gnir'
>>> s[0:3:-1]
''
>>> s[2::-1]
'sym'
Run Code Online (Sandbox Code Playgroud)
很好,如果步骤为负,则默认值相反.省略的第一个索引默认为要切片的字符串的大小,省略的第二个索引默认为零:
>>> s[len(s):3:-1]
'gnir'
Run Code Online (Sandbox Code Playgroud)
看起来不错!
>>> s[2:0:-1]
'sy'
Run Code Online (Sandbox Code Playgroud)
哎呦.错过了'我'.
然后是每个人最喜欢的字符串反向声明.它很甜蜜:
>>> s[::-1]
'gnirtsym'
Run Code Online (Sandbox Code Playgroud)
然而:
>>> s[len(s):0:-1]
'gnirtsy'
Run Code Online (Sandbox Code Playgroud)
切片永远不会包含切片中第二个索引的值.我可以看到这样做的一致性.
所以我想我开始理解切片在各种排列中的行为.但是,我感觉第二个索引有点特殊,并且负步骤的第二个索引的默认值实际上不能用数字来定义.
任何人都可以简明地定义可以解释所提供示例的默认切片索引吗?文档将是一个巨大的优势.
在玩NSAttributedString时,我遇到了一些来自UITextView的奇怪行为.说我有两个属性:
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UITextView *textView;
Run Code Online (Sandbox Code Playgroud)
在这些属性的拥有控制器中,我有以下代码:
NSDictionary *attributes = @{NSFontAttributeName : [UIFont systemFontOfSize:20.],
NSForegroundColorAttributeName: [UIColor redColor]};
NSAttributedString *as = [[NSAttributedString alloc] initWithString:@"Hello there!" attributes:attributes];
NSMutableAttributedString *mas = [[NSMutableAttributedString alloc] initWithString:@"Hello where?" attributes:nil];
[mas addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(3, 5)];
self.label.attributedText = as;
self.label.attributedText = mas;
self.textView.attributedText = as;
self.textView.attributedText = mas;
Run Code Online (Sandbox Code Playgroud)
在模拟器中运行时,标签使用系统默认字体查看(呃,使用您的想象力),如下所示:
<black>Hel</black><yellow>lo wh</yellow><black>ere?</black>
Run Code Online (Sandbox Code Playgroud)
使用大小为20.0的系统字体,文本视图如下所示:
<red>Hel</red><yellow>lo wh</yellow><red>ere?</red>
Run Code Online (Sandbox Code Playgroud)
看起来文本视图组合了两个属性字符串的属性.我发现这是一个令人惊讶的结果,并期望它表现得像标签.
我怀疑这是一个错误.如果不是,UITextView如何以及为什么以不同于UILabel的方式处理attributionText?
(XCode版本4.5.1)
UIKeyboardFrameBeginUserInfoKey和UIKeyboardFrameEndUserInfoKey之间的区别是什么?
这是否意味着"开始"一个返回的值与"结束"返回的值不同?
谢谢 !
我已经看到一些示例代码让我想知道在超类中调用指定的初始化程序.说我有一些代码:
@interface NewTableViewCell : UITableViewCell {
}
@end
@implementation NewTableViewCell
- (id) initWithFrame: (CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Do some stuff
}
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
注意,这initWithFrame
是指定的初始化程序UIView
,而不是UITableView
.这段代码应该始终在调用[UITableViewCell initWithStyle:reuseIdentifier:]
,还是取决于编码器的意图?
ios ×4
constants ×1
keyboard ×1
objective-c ×1
python ×1
slice ×1
uicolor ×1
uilabel ×1
uitextfield ×1
uitextview ×1