diff --git a/PopoverView/PopoverView.m b/PopoverView/PopoverView.m old mode 100644 new mode 100755 index 1bf43b5..7a48f57 --- a/PopoverView/PopoverView.m +++ b/PopoverView/PopoverView.m @@ -159,9 +159,13 @@ - (CGSize) screenSize - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withText:(NSString *)text { UIFont *font = kTextFont; - CGSize screenSize = [self screenSize]; - CGSize textSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(screenSize.width - kHorizontalMargin*4.f, 1000.f) lineBreakMode:UILineBreakModeWordWrap]; + CGRect textRect = [text boundingRectWithSize:CGSizeMake(screenSize.width - kHorizontalMargin*4.f, 1000.f) + options:NSStringDrawingUsesLineFragmentOrigin + attributes:@{NSFontAttributeName:font} + context:nil]; + + CGSize textSize = textRect.size; UILabel *textView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, textSize.width, textSize.height)]; textView.backgroundColor = [UIColor clearColor]; @@ -180,7 +184,12 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)t UIFont *font = kTextFont; CGSize screenSize = [self screenSize]; - CGSize textSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(screenSize.width - kHorizontalMargin*4.f, 1000.f) lineBreakMode:UILineBreakModeWordWrap]; + CGRect textRect = [text boundingRectWithSize:CGSizeMake(screenSize.width - kHorizontalMargin*4.f, 1000.f) + options:NSStringDrawingUsesLineFragmentOrigin + attributes:@{NSFontAttributeName:font} + context:nil]; + + CGSize textSize = textRect.size; UILabel *textView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, textSize.width, textSize.height)]; textView.backgroundColor = [UIColor clearColor]; @@ -269,7 +278,8 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)t UIView *container = [[UIView alloc] initWithFrame:CGRectZero]; //Create a label for the title text. - CGSize titleSize = [title sizeWithFont:kTitleFont]; + CGSize titleSize = [title sizeWithAttributes:@{NSFontAttributeName:kTitleFont}]; + //CGSize size = [string sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17.0f]}]; UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.f, 0.f, titleSize.width, titleSize.height)]; titleLabel.backgroundColor = [UIColor clearColor]; titleLabel.font = kTitleFont; @@ -356,7 +366,7 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withStringArray:(NSArra UIFont *font = kTextFont; for (NSString *string in stringArray) { - CGSize textSize = [string sizeWithFont:font]; + CGSize textSize = [string sizeWithAttributes:@{NSFontAttributeName:font}]; UIButton *textButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, textSize.width, textSize.height)]; textButton.backgroundColor = [UIColor clearColor]; textButton.titleLabel.font = font; @@ -381,7 +391,7 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)t UIFont *font = kTextFont; for (NSString *string in stringArray) { - CGSize textSize = [string sizeWithFont:font]; + CGSize textSize = [string sizeWithAttributes:@{NSFontAttributeName:kTitleFont}]; UIButton *textButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, textSize.width, textSize.height)]; textButton.backgroundColor = [UIColor clearColor]; textButton.titleLabel.font = font; @@ -428,7 +438,7 @@ - (NSMutableArray*) makeTempViewsWithStrings:(NSArray *)stringArray andImages:(N NSString *string = [stringArray objectAtIndex:i]; //First we build a label for the text to set in. - CGSize textSize = [string sizeWithFont:font]; + CGSize textSize = [string sizeWithAttributes:@{NSFontAttributeName:font}]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, textSize.width, textSize.height)]; label.backgroundColor = [UIColor clearColor]; label.font = font;