在iOS 6中使用自动布局时,UIButton的内在内容大小似乎包含按钮文本周围约10px的填充.有没有办法控制这个填充值?例如,我希望能够做到这样的事情,将每边的填充设置为5px:
[button setPadding:UIEdgeInsetsMake(5, 5, 5, 5)];
Run Code Online (Sandbox Code Playgroud)
我试过设置contentEdgeInsets,titleEdgeInsets和imageEdgeInsets都无济于事.奇怪的是,在contentEdgeInsets中指定负左值或右值似乎有一些效果,但不是顶部或底部.
无论哪种方式,我希望能够将实际填充值指定为正数,而不是将默认值调整为表示为负数.任何人都知道这是否可行?
根据Swift编程语言参考,无论何时将字典实例传递给函数/方法或将其分配给常量或变量,都会复制字典实例.这似乎效率低下.有没有办法在两种方法之间有效地共享字典的内容而不复制?
使用NSLayoutConstraint该类,可以创建基于视图基线(NSLayoutAttributeBaseline)的约束.但是,我没有看到任何描述如何UIView实际为自动布局系统提供基线值的文档.
如果我想创建一个定义UIView基线的自定义子类,我该怎么做?NSView定义了baselineOffsetFromBottom一种我认为在OS X上以某种方式涉及的方法,但是这在iOS中是如何工作的?
HTML 5规范描述了用于选择要在多部分表单提交中使用的字符编码的算法(例如,UTF-8).但是,不清楚如何将所选编码中继到服务器,以便可以在接收端正确解码内容.
通常,通过在Content-Type请求标头的值中附加"charset"参数来表示字符编码.但是,似乎没有为multipart/form-dataMIME类型定义此参数:
https://tools.ietf.org/html/rfc7578#section-8
多部分表单提交中的每个部分都可以提供自己的Content-Type标题; 但是,RFC 7578指出"实际上,许多广泛部署的实现不会在每个部分中提供字符集参数,而是依赖于'默认字符集'的概念,用于多部分/表单数据实例".
RFC 7578继续建议隐藏的"_charset_"表单字段可用于此目的.但是,Safari(9.1)和Chrome(51)似乎都没有填充此字段,也没有提供任何每部分编码信息.
我查看了两个浏览器生成的请求标头,但没有看到任何明显的字符编码信息.有谁知道浏览器如何将这些信息传达给服务器?
在Callable中处理Thread.interrupted()的正确方法是什么?我猜测callable应该抛出InterruptedException; 例如:
public class MyCallable implements Callable<Object> {
public Object call() {
Object result = null;
// Simulate long-running operation that calculates result
while (true) {
...
if (Thread.interrupted()) {
throw new InterruptedException();
}
}
result = ... // something produced by the long-running operation
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
这是正确的,还是有更合适的方法来处理它?谢谢.
我正在尝试在游乐场中使用自定义框架,如Apple文档中所述:
http://help.apple.com/xcode/mac/9.0/#/devc9b33111c
但是,我无法让操场识别框架(https://github.com/gk-brown/MarkupKit).它是一个定义模块的64位Objective-C框架.
这是我尝试过的:
菜单项实际上命名为"添加文件..."并被禁用.我可以通过打开Navigator面板并选择Project Navigator来解决这个问题.菜单项更改为"将文件添加到TestPlayground"并启用.
按照文件中的指示继续:
控制台显示以下错误:
error: TestPlayground.playground:5:8: error: no such module 'MarkupKit'
Run Code Online (Sandbox Code Playgroud)
该文档还指出,工作空间必须至少包含一个构建目标的活动方案.但是,将项目添加到工作区并构建它不能解决问题.操场仍然无法看到框架.
根据我在其他地方读到的SO,似乎这应该是可能的.但是,我发现的大多数信息都是2 - 3年,可能已经过时了.该框架是一个通用的二进制文件,我已尝试使用lipo修剪它,如其他一些帖子中所建议的那样.具体来说,我这样做了:
https://github.com/gk-brown/MarkupKit/wiki/Deployment
不幸的是,它没有帮助.
任何建议将非常感谢.
我正在尝试使用该objc_getProtocol()函数来获取对表示NSApplicationDelegate协议的结构的引用:
Protocol *protocol = objc_getProtocol("NSApplicationDelegate");
Run Code Online (Sandbox Code Playgroud)
但是,出于某种原因,这总是会回归NULL.
其他协议,如NSObject,NSCoding,NSTableViewDelegate,和NSTableViewDataSource做工精细.
有什么特别之处NSApplicationDelegate,或者我做错了什么?
cocoa protocols objective-c objective-c-runtime nsapplication
我正在尝试动态确定Objective-C中属性的类型.根据我在本网站和其他地方的内容,我相信我做的是正确的.但是,我的代码无效.
下面的代码片段演示了这个问题.尝试获取"backgroundColor"和"frame"的属性信息(两者都是UIView的有效属性)失败(class_getProperty()返回NULL):
id type = [UIView class];
objc_property_t backgroundColorProperty = class_getProperty(type, "backgroundColor");
fprintf(stdout, "backgroundColorProperty = %d\n", (int)backgroundColorProperty); // prints 0
objc_property_t frameProperty = class_getProperty(type, "frame");
fprintf(stdout, "frameProperty = %d\n", (int)frameProperty); // prints 0
Run Code Online (Sandbox Code Playgroud)
描述枚举的属性在这里没有产生预期的结果,无论是.以下代码:
NSLog(@"Properties for %@", type);
unsigned int outCount, i;
objc_property_t *properties = class_copyPropertyList(type, &outCount);
for (i = 0; i < outCount; i++) {
objc_property_t property = properties[i];
fprintf(stdout, "%s %s\n", property_getName(property), property_getAttributes(property));
}
Run Code Online (Sandbox Code Playgroud)
生成此输出:
2012-03-09 13:18:39.108 IOSTest[2921:f803] Properties for UIView
caretRect T{CGRect={CGPoint=ff}{CGSize=ff}},R,N,G_caretRect
gesturesEnabled Tc,N
deliversTouchesForGesturesToSuperview …Run Code Online (Sandbox Code Playgroud) 我最近向Apple提交了一个关于此问题的错误报告,但我想我会问这个问题,以防万一我遗漏了一些明显的东西.在Objective-C中,以下调用在64位系统上正常工作,但在32位系统上抛出NSInvalidArgumentException:
[self setValue:@"true" forKey:@"flag"];
Run Code Online (Sandbox Code Playgroud)
"flag"属性是BOOL:
@property BOOL flag;
Run Code Online (Sandbox Code Playgroud)
此外,调用在Swift/32位中工作正常,其中属性是Bool:
var flag: Bool = false
Run Code Online (Sandbox Code Playgroud)
类似地,此调用在64位系统上在Swift中正常工作,但在32位系统上抛出NSInvalidArgumentException("index"是Int):
setValue("2", forKey: "index")
Run Code Online (Sandbox Code Playgroud)
然而它在Objective-C/32-bit中运行良好,其中属性是NSInteger.
无论语言或处理器架构如何,我都希望这些调用能够正常工作.有没有人对他们为什么不这样做有所了解?
我的控制器中有以下简单的测试代码:
- (void)loadView
{
UIView *view = [UIView new];
[self setView:view];
UILabel *label = [UILabel new];
[label setText:@"Hello World!"];
[view addSubview:label];
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[label]"
options:0 metrics:nil views:NSDictionaryOfVariableBindings(label)]];
}
Run Code Online (Sandbox Code Playgroud)
代码失败,出现以下异常,我无法弄清楚原因.任何帮助将不胜感激:
2013-04-15 14:15:47.880 libmarkup-test[1072:c07] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. > Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or …Run Code Online (Sandbox Code Playgroud) ios ×4
autolayout ×3
objective-c ×3
swift ×2
32-bit ×1
64-bit ×1
callable ×1
cocoa ×1
dictionary ×1
frameworks ×1
future ×1
html ×1
java ×1
kvc ×1
post ×1
properties ×1
protocols ×1
uibutton ×1
uiedgeinsets ×1
uiview ×1
utf-8 ×1
xcode ×1