cbess/AutoScrollLabel

iOS 8 sizeWithFont deprecated

Closed this issue · 4 comments

due to the fact that sizeWithFont is deprecated in IOS8 there is a need to change this:

CGSize labelSize = [self.mainLabel.text sizeWithFont:self.mainLabel.font
                                       constrainedToSize:CGSizeMake(CGFLOAT_MAX,    
                                       CGRectGetHeight(self.bounds))];

with:

CGRect labelSize = [self.mainLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 
                                CGRectGetHeight(self.bounds))
                                options:NSStringDrawingUsesLineFragmentOrigin
                                attributes:@{NSFontAttributeName:self.mainLabel.font}
                                context:nil];

and them change the labelSize.width for labelSize.size.width

I welcome pull requests or you can wait on me to fix it.

in 6 6plus scroll abnormal

why not use sizeToFit on each label?

each_object(self.labels, ^(UILabel *label) {

    [label sizeToFit];
    label.frame = CGRectMake(offset, 0, CGRectGetWidth(label.frame), CGRectGetHeight(self.bounds));

    // Recenter label vertically within the scroll view
    label.center = CGPointMake(label.center.x, roundf(self.center.y - CGRectGetMinY(self.frame)));

    offset += roundf(CGRectGetWidth(label.bounds) + self.labelSpacing);
});
cbess commented

Fixed in #44