Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15374] iOS7: Add disabledColor property

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-10-29T21:39:48.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 22, 2013 Sprint 22 API, Release 3.2.0
ComponentsiOS
LabelsbackgroundSelectedImage, button, ios, module_button, qe-testadded, triage
ReporterMostafizur Rahman
AssigneeVishal Duggal
Created2013-09-30T02:14:09.000+0000
Updated2014-07-18T15:48:58.000+0000

Description

New backgroundSelectedImage property for iOS button. Workaround made by "click" listener and some function for changing backgroundImage doesn't work properly if user hold finger on the button or if user uses more fingers etc. It is hard to fix all these options. For good UX is backgroundSelectedImage necessary.

Attachments

FileDateSize
Resources.zip2013-10-28T20:53:25.000+00007949

Comments

  1. Ingo Muschenetz 2013-09-30

    Is this a property on native buttons in iOS? Is this only for iOS? Does this property exist/work on other platforms already?
  2. Matej 2013-09-30

    Hi Ingo 1. If I understand it then yes you can set it by backgroundImageForState (UIControlStateDisabled, UIControlStateSelected etc...) 2. Yes this requirement is only for iOS (iPhone/iPad) 3. This property works on Android, Web Mobile and Tizen. (http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.Button-property-backgroundSelectedImage)
  3. Ygor Lemos 2013-10-23

    This should be on 3.2.0 as iOS7 basically flattened almost everything, many buttons have flat color backgrounds, that said, with current Ti versions it is impossible to give the user accurate button pressing feedback (unless using a lot of eventlisteners everywhere). On Android this works perfectly and for parity this should exist for iOS as well. On Interface Builder you can configure backgroundColor, backgroundImage and text color (selectedColor) for all those button states: Default, Highlighted, Selected and Disabled. So basically, selectedColor, backgroundSelectedColor, backgroundSelectedImage, backgroundFocusedColor, backgroundFocusedImage, backgroundDisabledColor, backgroundDisabledImage should all be mapped to work under iOS as this is possible with the native SDK without using events, simply by setting the color / images on Interface Builder.
  4. Matej 2013-10-23

  5. Ingo Muschenetz 2013-10-24

    Any additional sample code or test cases would be appreciated.
  6. Malcolm Hollingsworth 2013-10-26

    I agree with Ygor, all need mapping if they already exist. Seems like an easy parity gain and makes ios7 state work as it should as well as not creating unforeseen memory leaks with badly coded event listeners.
  7. Ingo Muschenetz 2013-10-28

    Note that we support backgroundSelectedImage, backgroundFocusedImage backgroundDisabledImage properties. Do you have references for the corresponding *Color properties?
  8. Vishal Duggal 2013-10-28

    Test Case Files attached
  9. Vishal Duggal 2013-10-28

    We already support backgroundImage,backgroundSelectedImage,backgroundDisabledImage properties. We also support color, selectedColor and backgroundColor properties. We will add support for disabledColor property. We will not support backgroundDisabledColor and backgroundSelectedColor properties on iOS.
  10. Vishal Duggal 2013-10-28

    Pull pending against master https://github.com/appcelerator/titanium_mobile/pull/4870
  11. Matej 2013-10-29

    *Vishal Duggal*, please can I ask you why will not support backgroundSelectedColor? On Android this property does work. My problem is (For sure it is not only my problem) that I have in my application approx. 15 buttons with different backgroundColor and everywhere I used backgroundSelectedColor because it is much easier than make 3+ images for one button (iOS) and few next for Android... This property saves a lot of time + space. + What is faster/better for app. performance? Window (Menu) with 6/8 buttons that contain image or 6/8 buttons with bgColor? Thank you
  12. Ingo Muschenetz 2013-10-29

    [~sko] The issue is that AFAIK, backgroundSelectedColor is not natively available on iOS. Hacking around this for parity's sake can lead to a very fragile SDK. Can you point to documentation or a simple workaround that suggests otherwise?
  13. Matej 2013-10-29

    Ou, sorry I didn't know that. I have seen only backgroundImage property as I mentioned above...anyway thanks for clarification.
  14. Malcolm Hollingsworth 2013-10-29

    I am confused by all the comments; Will "backgroundDisabledColor" be supported and if not what was the reasoning?
  15. Matej 2013-10-29

    backgroundDisabledColor will not supported probably for same reason as backgroundSelectedColor (Properties are not available natively on iOS)
  16. Malcolm Hollingsworth 2013-10-29

    Thanks, I just delved further into the classes than I normally feel comfortable with - nothing about background colour states - annoying but true. Cheers
  17. Ygor Lemos 2013-10-29

    @Ingo Actually you only have textcolor, background image and shadows to set on IB per button state. In order to change the selected color you need to tinker with the layers that form the button itself and override the Highglighted state layer. something like:
        - (void) setHighlighted:(BOOL)highlighted {
            [super setHighlighted:highlighted];
        
            if (highlighted) {
                self.backgroundColor = UIColorFromRGB(0x387038);
            }
            else {
                self.backgroundColor = UIColorFromRGB(0x5bb75b);
            }
        }
        
    So if we want to make parity for this, we should focus on UIControl and play with UIControlStateHighlighted. More on: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIControl_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIControlState I've also seen some solutions based on creating an image on-the-fly with the desired color and applying it as the background for the selected state with setBackgroundImage:forState: as in:
        - (UIImage *)imageWithColor:(UIColor *)color {
           CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
           UIGraphicsBeginImageContext(rect.size);
           CGContextRef context = UIGraphicsGetCurrentContext();
        
           CGContextSetFillColorWithColor(context, [color CGColor]);
           CGContextFillRect(context, rect);
        
           UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
           UIGraphicsEndImageContext();
        
           return image;
        }
        
        [myButton setBackgroundImage:[self imageWithColor:[UIColor greenColor]] forState:UIControlStateHighlighted];
        
    AFAIK those are the only current ways to achieve a backgroundSelectedColor on iOS.
  18. Wilson Luu 2013-11-26

    Closing ticket as fixed. Verified the Button.disabledColor is working as expected i.e. if a button is disabled, then the button's text color will be set to Button.disabledColor property. Also, the disabledColor property works on both iOS 6 and iOS 7 devices. Tested on: Titanium Studio, build: 3.2.0.201311221859 SDK build: 3.2.0.v20131122172908 CLI: 3.2.0-alpha Alloy: 1.3.0-alpha6 Xcode: 5.0.2 Device: iphone 5 (6.1.3), iphone 5 (7.0.2) Related doc tickets: TIDOC-1382: disabledColor property needs to be documented TIDOC-1383: backgroundSelectedImage property is not documented for iOS TIDOC-1384: backgroundDisabledImage property is not documented for iOS

JSON Source