UILabelまたは他のコントロール(UIButton、UITextFieldなど)のカテゴリクラスを作成します。
UILabel + DynamicFontSize。時間
#import <UIKit/UIKit.h>
@interface UILabel (DynamicFontSize)
@property (nonatomic) IBInspectable BOOL adjustFontSize;
@end
UILabel + DynamicFontSize.m
#import "UILabel+DynamicFontSize.h"
@implementation UILabel (DynamicFontSize)
@dynamic adjustFontSize;
-(void)setAdjustFontSize:(BOOL)adjustFontSize{
if (adjustFontSize)
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.font = [self.font fontWithSize:self.font.pointSize*(screenBounds.size.width/320)]; // 320 for iPhone 5(320x568) storyboard design
// if you design with iphone 6(375x667) in storyboard, use 375 instead of 320 and iphone 6 plus(414x736), use 414
}
}
@end
使用
は、任意のラベルを選択し、[プロパティ名がON
にフォントサイズの変更値を調整して見つけます
あなたのプロジェクトで大きなフォントを使用して、自動縮尺で行数を設定すると、ラベルのサイズを使ってフォントを縮小します – Tj3n
サイズクラスを使用してアーカイブすることができます –
@SagarBhut 、どのようにサイズクラスで達成する。 – srinadh