UIButton字体不流畅

时间:2012-01-05 09:15:20

标签: ios uibutton

我在视图中添加了一些UIButton,但按钮中的字体似乎不平滑(在视网膜屏幕中)....

查看图片:enter image description here

有人帮忙吗?谢谢!

以下是我添加按钮的方法:

- (void)setItems:(NSArray *)items {
    if (_items != items) {
        _items = items;
        for (UIView *v in self.containerView.subviews) {
            [v removeFromSuperview];
        }
        int i = 1;
        CGFloat y = 8;
        for (id item in _items) {
            UIButton *itemButton = [UIButton buttonWithType:UIButtonTypeCustom];
            itemButton.frame = CGRectMake(0, y, self.containerView.bounds.size.width, 35);
            itemButton.tag = i;
            [itemButton setTitle:item forState:UIControlStateNormal];
            [itemButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [itemButton setBackgroundImage:[UIImage imageNamed:@"bg.png"] forState:UIControlStateHighlighted];
            itemButton.titleLabel.font = [UIFont boldSystemFontOfSize:20];
            [itemButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
            y += 35;
            [self.containerView addSubview:itemButton];
            i++;
        }
    }
}

1 个答案:

答案 0 :(得分:1)

问题解决了:

self.containerView = [[UIScrollView alloc] initWithFrame:frame];
UIScreen *mainScreen = [UIScreen mainScreen];
if ([mainScreen respondsToSelector:@selector(scale)]) {
    self.containerView.contentScaleFactor = mainScreen.scale;
}

self.containerView.contentScaleFactor = mainScreen.scale;