robertwijas / UISS

UIAppearance Stylesheets
MIT License
1.23k stars 80 forks source link

UIButton titleColor not working - swift #53

Closed ypawar82 closed 7 years ago

ypawar82 commented 7 years ago

Hi,

I'm using Swift 3.0. "titleColor:highlighted": "white" This is not working. Also i tried UISS pod but error [!] Unable to find a specification for UISS (~> 1.1.0) Also there is no class UIButton+UISS in my version from git. -Thanks !!

robertwijas commented 7 years ago

Can you paste here your Podfile and uiss.json file? BTW UIButton+UISS category is not needed.

ypawar82 commented 7 years ago

Hi,

Podfile contents

target 'MyOrder' do
  use_frameworks!
  pod 'UISS', '~> 1.1.0'
end

UISS json i'm using

{

    "Variables": {
        "tint":"#13A9FA"
    },
    "UIWindow": {
        "tintColor":"$tint"
    },
    "UITabBar": {
        "tintColor": "white"
    },
    "UINavigationBar": {
        "Phone": {
            "tintColor":"$tint",
            "titleTextAttributes": { "NSForegroundColorAttributeName":"#13A9FA"}
        }
    },
    "SubmitButton": {
        "backgroundColor": "#13A9FA",
        "titleColor":"white",
        "UILabel": {
            "font": ["Montserrat-Regular", 16],
            "textColor":"white"
        }

    }
}

SubmitButton is swift class with no extra body logic and is subclass of UIButton. I'm trying to change title color of UIButton. -Thanks !!

robertwijas commented 7 years ago

Try:

{
    "titleColor:normal": "white"
}
ypawar82 commented 7 years ago

I used { "titleColor:normal": "white" }

but app is not loading, only launch screen shows for long time.

robertwijas commented 7 years ago

I'll try creating a sample Swift 3.x project tomorrow.

ypawar82 commented 7 years ago

Thanks !!

For Swift project I'm using this function in UISSParser.m to use UISS with Swift 3.0 (referred in issue topics)

- (Class)classFromString:(NSString *)className {
    Class class = NSClassFromString(className);
    if (!class) {
        // if the class doesn't exist as a pure Obj-C class then try to retrieve it as a Swift class.
        NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
         //MyApp has hypen so modifying app name for sake to connect swift classes
        if ([appName isEqualToString:@"MyApp2-2"]) {   
            appName = @"MyApp2_2";
        }
        NSString *classStringName = [NSString stringWithFormat:@"_TtC%d%@%d%@", appName.length, appName, className.length, className];
               class = NSClassFromString(classStringName);
    }
    return class;
}

Above is called from this function

- (void)processKey:(NSString *)key object:(id)object context:(UISSParserContext *)context; {
    if ...
 else {
        //  Earlier version line commented    
       //  Class class = NSClassFromString(key);
        // For Swift class calling function classFromString
        Class class = [self classFromString:(key)];
        if (class) {
            [self processClass:class object:object context:context];
        } else {
            [self processPropertyWithKey:key value:object context:context];
        }
    }
}
robertwijas commented 7 years ago

Regarding CocoaPods, can you check the output of pod repo list? Do you have https://github.com/CocoaPods/Specs.git configured as your master CocoaPods repository?

robertwijas commented 7 years ago

So Swift classes are prefixed with module name. So for your custom class you need to use ModuleName.SubmitButton in uiss.json file. Also I recommend using the most recent UISS version which is 1.1.2.

Please let me know if you have any further questions.

robertwijas commented 7 years ago

@ypawar82 BTW I've created a sample project to confirm, please let me know if you'd like to have it. Thanks!

ypawar82 commented 7 years ago

Sure !! How can I access ?

robertwijas commented 7 years ago

@ypawar82 https://dl.dropboxusercontent.com/u/530014/UISSTestSwift.zip

ypawar82 commented 7 years ago

Thank you !! Appreaciate !! Works for me !!