我有一个UIButton,我在设置标题后调用@Override
protected void onResume() {
super.onResume();
camera = Camera.open(0);
setPreviewSize(FULL_SCREEN);
camera.setFaceDetectionListener(new Camera.FaceDetectionListener() {
@Override
public void onFaceDetection(Camera.Face[] faces, Camera camera) {
Log.i("FACES:", Integer.toString(faces.length));
}
});
camera.startFaceDetection();
camera.autoFocus(new Camera.AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
Log.i("AUTOFOCUS", "AutoFocus: " +
(success ? "Succeeded" : "Failed"));
}
});
}
。在标题文本非常短(可能<20pt)的情况下,按钮在左侧和右侧采用几个填充点。任何更长的时间,填充消失。就好像按钮具有在调用sizeToFit
时所遵循的内部最小宽度一样。有谁知道如何防止这种填充?
答案 0 :(得分:0)
这样做,只需将字符串更改为任何内容,并享受调整大小的奇迹。
NSString * helloKitty = @"I love cats";
UIButton * ss = [UIButton buttonWithType:UIButtonTypeCustom];
[ss setTitle:helloKitty forState:UIControlStateNormal];
[[ss titleLabel] setFont:[UIFont systemFontOfSize:14]];
[ss setBackgroundColor:[UIColor pink] forState:UIControlStateNormal];
CGSize strSizer = [helloKitty sizeWithAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],
NSFontAttributeName:[UIFont systemFontOfSize:14]}];
[ss setFrame:CGRectMake(100,200,strSizer.width, strSizer.height)];
[self.view addSubview:ss];