GitHub Issue | n/a |
Type | New Feature |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-10-29T21:39:48.000+0000 |
Affected Version/s | n/a |
Fix Version/s | 2013 Sprint 22, 2013 Sprint 22 API, Release 3.2.0 |
Components | iOS |
Labels | backgroundSelectedImage, button, ios, module_button, qe-testadded, triage |
Reporter | Mostafizur Rahman |
Assignee | Vishal Duggal |
Created | 2013-09-30T02:14:09.000+0000 |
Updated | 2014-07-18T15:48:58.000+0000 |
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.
Is this a property on native buttons in iOS? Is this only for iOS? Does this property exist/work on other platforms already?
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)
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.
Any additional sample code or test cases would be appreciated.
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.
Note that we support backgroundSelectedImage, backgroundFocusedImage backgroundDisabledImage properties. Do you have references for the corresponding *Color properties?
Test Case Files attached
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.
Pull pending against master https://github.com/appcelerator/titanium_mobile/pull/4870
*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
[~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?
Ou, sorry I didn't know that. I have seen only backgroundImage property as I mentioned above...anyway thanks for clarification.
I am confused by all the comments; Will "backgroundDisabledColor" be supported and if not what was the reasoning?
backgroundDisabledColor will not supported probably for same reason as backgroundSelectedColor (Properties are not available natively on iOS)
Thanks, I just delved further into the classes than I normally feel comfortable with - nothing about background colour states - annoying but true. Cheers
@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:
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:
AFAIK those are the only current ways to achieve a backgroundSelectedColor on iOS.
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