1

IBでボタンを作成し、タイプのみをカスタム、タイトル、フォントサイズに設定すると、見栄えがよくなります。プログラムで作成すると、フォントがぼやけてしまいます。ボタンを作成するコードは次のとおりです。

CGRectフレーム=self.sendButton.frame;

    NSString *title = @"Read Disclosure";
    UIFont *font = [UIFont boldSystemFontOfSize:17.0];
    CGSize titleSize = [title sizeWithFont:font constrainedToSize:frame.size];

    CGFloat xValue = (self.view.frame.size.width - titleSize.width) / 2;
    CGFloat yValue = frame.origin.y - (titleSize.height / 2);

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    [button setFrame:CGRectMake(xValue, yValue, titleSize.width, titleSize.height * 2)];
    [button setTitle:@"Read Disclosure" forState:UIControlStateNormal];
    [button.titleLabel setFont:font];
    [button setTitleColor:[UIColor colorWithRed:50.0/255.0 green:79.0/255.0 blue:133.0/255.0 alpha:1.0] forState:UIControlStateNormal];
    [button setTitleShadowColor:nil forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [button addTarget:self action:@selector(disclosureButtonAction) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button];

私は考えられるすべての設定を試しましたが、何も違いはないようです。私がここで欠けているものについて何か考えはありますか?

ありがとう。

4

1 に答える 1

6

xフレームの、ywidth、およびheightが整数であることを確認する必要があります。round/ floor/を使用して手動でこれを行うか、それほど手動で制御する必要がない場合にceil使用します。CGRectIntegralおそらく、コード内の浮動小数点除算が原因で、ボタンが非整数ピクセル境界に落ちています。これはこの質問の複製です。

sizeWithFont:非整数の浮動小数点数も返す場合があることに注意してください。

于 2012-11-19T22:31:20.200 に答える