读苹果官方文档的一点小收获

  1. 将一个Label居中在一个View里

        NSString* exampleString = [NSString stringWithFormat:@"This is an example string"];
    CGSize stringSize = [noContentString sizeWithFont:[UIFont systemFontOfSize:18]];
    
    CGRect labelSize = CGRectMake((superview.size.width - stringSize.width) / 2.0,
                                (superview.size.height - stringSize.height) / 2.0,
                                stringSize.width, stringSize.height);
    
    UILabel* exampleLabel = [[UILabel alloc] initWithFrame:labelSize];
    exampleLabel.text = exampleString;
    exampleLabel.font = [UIFont systemFontOfSize:18];
    [superview addSubview:exampleLabel];
    
  2. 读文档看到没有见过的方法、属性等一定要查阅官方文档中相应的内容,这会有助于对代码或文档的理解。比如View Programming Guide for iOS文档中有这样一句:Use the screens property of UIScreen to obtain the screen object for the external display.我一开始看的时候不知道这是什么意思,但是查找到UIScreen Class Reference 中Task里的Getting the Available Screens有一个方法screens。文档里是这么写的:

    + screens
    Returns an array containing all of the screens attached to the device.
    
    Declaration:
    SWIFT
    class func screens() -> [UIScreen]
    OBJECTIVE-C
    + (NSArray<UIScreen *> *)screens
    
    Return Value:
    An array of UIScreen objects.
    
    Discussion:
    The returned array includes the main screen plus any additional screens connected to the device. The main screen is always at index 0.
    Not all devices support external displays. Currently, external displays are supported by iPhone and iPod touch devices with Retina displays and iPad. Older devices, such as the iPhone 3GS do not support external displays.
    

    这样我就知道了这个screens到底是怎么回事,调用UIScreen类的这个类方法,方法会返回一个包含设备所有屏幕的一个列表,其中index = 0时是mian screen。

  3. 不要急不要慌,认真学习,加油自己!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值