UICollectionViewFlowLayout 设置只有一个Item时居左显示

    SEL sel = NSSelectorFromString(@"_setRowAlignmentsOptions:");
    if ([_flowLayout respondsToSelector:sel]) {
        ((void(*)(id,SEL,NSDictionary*)) objc_msgSend)(_flowLayout,sel, @{@"UIFlowLayoutCommonRowHorizontalAlignmentKey":@(NSTextAlignmentLeft),@"UIFlowLayoutLastRowHorizontalAlignmentKey" : @(NSTextAlignmentLeft),@"UIFlowLayoutRowVerticalAlignmentKey" : @(NSTextAlignmentCenter)});
    }

参考文章:https://www.jianshu.com/p/de08c2679241

你可能感兴趣的:(UICollectionViewFlowLayout 设置只有一个Item时居左显示)