All Projects → freedom-shen → ObjCUI

freedom-shen / ObjCUI

Licence: MIT license
使用OC来写声明氏UI

Programming Languages

objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to ObjCUI

TicTacToe-SwiftUI
Unidirectional data flow tic-tac-toe sample with SwiftUI.
Stars: ✭ 22 (-18.52%)
Mutual labels:  swiftui
SwiftUI.TextEdit
SwiftUI proof-of-concept text edit component
Stars: ✭ 71 (+162.96%)
Mutual labels:  swiftui
Cloe
Cloe is Redux on Combine for SwiftUI with excellent feng shui.
Stars: ✭ 29 (+7.41%)
Mutual labels:  swiftui
awesome-result-builders
A list of cool DSLs made with Swift 5.4’s @resultBuilder
Stars: ✭ 805 (+2881.48%)
Mutual labels:  swiftui
SwiftUIKit
📱 UIKit code that is fun to write
Stars: ✭ 71 (+162.96%)
Mutual labels:  swiftui
Scre
A lightweight screen recorder macOS application written in SwiftUI.
Stars: ✭ 53 (+96.3%)
Mutual labels:  swiftui
macos-snippets
Snip is a lightweight snippets manager app for macOS
Stars: ✭ 238 (+781.48%)
Mutual labels:  swiftui
Columbus
A feature-rich country picker for iOS, tvOS and watchOS.
Stars: ✭ 23 (-14.81%)
Mutual labels:  swiftui
Redux
Manage iOS App state with Redux and Async/Await :)
Stars: ✭ 18 (-33.33%)
Mutual labels:  swiftui
Shibuya
An Xcode theme to solve some problems with default theme on SwiftUI
Stars: ✭ 38 (+40.74%)
Mutual labels:  swiftui
SwiftUI-learning
SwiftUI视频教程配套代码(SwiftUI+SwiftUI 2.0+SwiftUI 3.0)+SwiftUI macOS+其他
Stars: ✭ 57 (+111.11%)
Mutual labels:  swiftui
LunarCalendar
A lightweight macOS App for displaying calendar and time
Stars: ✭ 82 (+203.7%)
Mutual labels:  swiftui
Tasky
Tasky is a task management app made with SwiftUI.
Stars: ✭ 22 (-18.52%)
Mutual labels:  swiftui
tca-swiftui-navigation-demo
Demo project that shows how to implement navigation in SwiftUI iOS application using Swift Composable Architecture
Stars: ✭ 75 (+177.78%)
Mutual labels:  swiftui
SwiftUIFormValidator
Declarative form validator for SwiftUI.
Stars: ✭ 34 (+25.93%)
Mutual labels:  swiftui
SwiftUIAlarm
⏰ An example Alarm-like app using SwiftUI which is introduced in WWDC19
Stars: ✭ 36 (+33.33%)
Mutual labels:  swiftui
CoreDataToSwiftUI
Rule based CRUD CoreData Frontends for SwiftUI
Stars: ✭ 18 (-33.33%)
Mutual labels:  swiftui
BetterWeather
The missing Apple Weather App for Mac.
Stars: ✭ 19 (-29.63%)
Mutual labels:  swiftui
SwiftUI-Color-Kit
SwiftUI Color Pickers, Gradient Pickers And All The Utilities Needed To Make Your Own!
Stars: ✭ 120 (+344.44%)
Mutual labels:  swiftui
kotlin-simple-architecture
Kotlin Simple Architecture
Stars: ✭ 35 (+29.63%)
Mutual labels:  swiftui

ObjCUI

Version License Platform

About

在iOS开发中, 由于xib(storyboard)的维护问题,所以一般的开发者都习惯使用Masonary来构建UI。虽然可维护性提高了,但是不得不说开发效率上有所牺牲。 ObjcUI参考Flutter(SwiftUI),尝试使用声明氏的UI来提高一定的开发效率。

Demo

普通的UIKit,以UILabel为例

// before
UILabel *label = [[UILabel alloc] init];
label.text = @"test";
label.textColor = [UIColor redColor];
label.backgroundColor = [UIColor whiteColor];
label.font = [UIFont systemFontOfSize:12];
label.textAlignment = NSTextAlignmentCenter;

// after
UILabel.objc_create().objc_text(@"test").objc_textColor([UIColor redColor]).objc_backgroundColor([UIColor redColor])
        .objc_font([UIFont systemFontOfSize:12]).objc_textAlignment(NSTextAlignmentCenter);

可以把UIControl的点击事件放入同一代码逻辑中

// before
- (void)buttonTouch:(UIButton *)sender {
    NSLog(@"点击了按钮");
}

UIButton *button = [[UIButton alloc] init];
[button setTitle:@"我来做个测试" forState:UIControlStateNormal];
[button addTarget:self action:@selector() forControlEvents:UIControlEventTouchUpInside];

// after 
UIButton *button = UIButton
        .objc_create()
        .objc_title(UIControlStateNormal, @"我来做个测试")
        .objc_actionControl(UIControlEventTouchUpInside, ^(UIButton *button) {
            NSLog(@"点击了按钮");
        });

更可以把DataSource,Delegate也统一起来

self.view = UITableView
        .objc_create()
        .objc_registerClassForCellReuseIdentifier([UITableViewCell class], @"cell")
        .objc_numberOfRowsInSection(^NSInteger(UITableView *tableView, NSInteger section) {
            return 100;
        })
        .objc_cellForRowAtIndexPath(^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath) {
            UITableViewCell *tableViewCell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            tableViewCell.textLabel.text = @(indexPath.row).stringValue;
            return tableViewCell;
        })
        .objc_heightForRowAtIndexPath(^CGFloat(UITableView *tableView, NSIndexPath *indexPath) {
            return indexPath.row % 2 == 0 ? 50 : 100;
        })
        .objc_didSelectRowAtIndexPath(^(UITableView *tableView, NSIndexPath *indexPath) {
            [tableView deselectRowAtIndexPath:indexPath animated:YES];
            NSLog(@"did select At index path row : %zd", indexPath.row);
        });

Layout

在UIView中已存在对于Masonary的映射方法

// layout 
XXX.objc_putSuperView(self.view, ^(MASConstraintMaker *maker) {
                maker.top.mas_equalTo(100);
                maker.width.height.mas_equalTo(100);
            });

除此之外添加了Padding,Row,Column等容器控件的支持

// OCUIColumn
self.view.objc_convertColumn.objc_children(@[
        UIView...
]);

// OCUIRow
self.view.objc_convertColumn.objc_children(@[
        UIView...
]);

// OCUIPadding 
self.view.objc_convertPadding.objc_child(
    UIView...
);

// Center
self.view.objc_convertCenter.objc_child(
    UIView...
);

Installation && Author

pod 'ObjCUI'

沈晓敏, [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].