首页 > 移动平台 > 详细

swift appearanceWhenContainedIn:(version1.2 xcode6.4)

时间:2015-07-15 02:28:00      阅读:254      评论:0      收藏:0      [点我收藏+]

?

swift1.2中没有oc中对应的方法:

+ (instancetype)appearanceWhenContainedIn:(Class <UIAppearanceContainer>)ContainerClass, ... NS_REQUIRES_NIL_TERMINATION;

?解决方法:

在swift项目中新建oc类如下:

#import <UIKit/UIKit.h>

@interface UIView (UIAppearance_Swift)
+ (instancetype)ls_appearanceWhenContainedWithin: (NSArray *)containers;

@end

?

#import "UIView+UIAppearance_Swift.h"

@implementation UIView (UIAppearance_Swift)
+ (instancetype)ls_appearanceWhenContainedWithin: (NSArray *)containers
{
    NSUInteger count = containers.count;
    NSAssert(count <= 10, @"The count of containers greater than 10 is not supported.");
    
    return [self appearanceWhenContainedIn:
            count > 0 ? containers[0] : nil,
            count > 1 ? containers[1] : nil,
            count > 2 ? containers[2] : nil,
            count > 3 ? containers[3] : nil,
            count > 4 ? containers[4] : nil,
            count > 5 ? containers[5] : nil,
            count > 6 ? containers[6] : nil,
            count > 7 ? containers[7] : nil,
            count > 8 ? containers[8] : nil,
            count > 9 ? containers[9] : nil,
            nil];
}
@end

?swift调用即可。

?

BTW:

在xcode7beta,swift2中提供此方法:

    @available(iOS 9.0, *)
    static func appearanceWhenContainedInInstancesOfClasses(containerTypes: [AnyObject.Type]) -> Self

?

?

?

?

?

swift appearanceWhenContainedIn:(version1.2 xcode6.4)

原文:http://justsee.iteye.com/blog/2227009

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!