[TIMOB-17340] TiAPI: Text - Add lineHeight property to Ti.UI.Label and Ti.Ui.TextArea
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-11-13T23:56:39.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 7.0.0 |
Components | Android |
Labels | feature |
Reporter | Jasper Kennis |
Assignee | Gary Mathews |
Created | 2014-06-26T08:32:15.000+0000 |
Updated | 2017-11-15T06:37:20.000+0000 |
Description
Conscious duplicate of poorly defined ticket TIMOB-6403.
Problem
Right now, Titanium doesn't have support for the line height property of text. Preferred behaviour would be to be able to have a propertylineHeight
, and the methods setLineHeight
and getLineHeight
, on Titanium.UI.Label
and Titanium.UI.TextArea
.
LineHeight would be set to control the vertical spacing between lines in a multiline label or textarea.
Available values should be 'normal'
, or any supported dimension measurement. 'normal'
would indicate the default lineHeight for the set fontsize, any other would apply as the platform it's run on handles it.
Test case
Inserting the following code in some window to get three labels. Expected result would be to have
var label1, label2, label3, view;
view = Ti.UI.createView({
height: 1000,
width: 100
});
label1 = Ti.UI.createLabel({
height: Ti.UI.SIZE,
left: 0,
lineHeight: 'normal',
right: 0,
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sed cursus nunc, id semper risus.',
top: 0
});
label2 = Ti.UI.createLabel({
height: Ti.UI.SIZE,
left: 0,
lineHeight: 20,
right: 0,
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sed cursus nunc, id semper risus.',
top: 200
});
label3 = Ti.UI.createLabel({
height: Ti.UI.SIZE,
left: 0,
lineHeight: 40,
right: 0,
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sed cursus nunc, id semper risus.',
top: 400
});
view.add(label1);
view.add(label2);
view.add(label3);
Hi, Thank you for your report. I will notice our engineer team about your new feature requirement. Hope they will get this feature done in near feature. Regards, Shuo
As in the description, I know it's duplicate, but that one was never picked up because it was too poorly defined. Does this mean it's not going to be picked up after all?
Using this ticket instead as it has a better definition. Resolved the other as a duplicate.
Hi--two questions: 1) Is this for all platforms, or just one specific one (iOS, Android, etc)? 2) Why TextArea?
1) Looking at the documentation I suspect it's all platforms. I've tested it on iOS only so far, and from what I read Android users are having the same experiences. 2) Because TextArea can also be multiline. You could say it's more important to have lineHeight on Label than on TextArea tho, maybe, since Label might be the view with more styling needs.
I would love to see the lineHeight property added for all platforms, especially for a Label but also for TextArea/TextField. Historically Titanium has been very bad at supporting high-quality, accurate UX, especially when it comes to text. This is one example. This property will help with the fundamental problem that on Android with a fixed component height the text is truncated or cropped horizontally. In other words, for example, if you require say a label of fixed height 40, and the font size is 12 (giving an approximate line height of about 15) on iOS it will render 2 lines of text. On Android it will render 2 lines and a third partial line with the bottom of the line chopped off. I believe that this is a feature of native Android, rather than Titanium. However, if one knew the line height one could set the label height to be an integer multiple of the line height and so this problem wouldn't occur. This is a solution to a particular problem. However from a graphic designer's or UX specialist's (which I am as well as a developer) point of view it is essential to be able to set the line height of a block of text. I know we have some finer controls now with attributed text, but this is very limited on Android and we really need to be able to get and set the line height of text. And as an aside, can we please have ellipsis work on Android for multi-line text (wordWrap = true) as it does work perfectly on iOS.
+1 It's PITA to fix every multiline text on Android. :(
+1 Been waiting years for this basic attribute
Hello :) , im not quite sure what is meant by lineHight ? The actual label to be resized to match the text font size automatically ? Or for the hight of the text inside the label ?
Maybe this is a solution : https://github.com/TTTAttributedLabel/TTTAttributedLabel , it supports linespacing
Angel Petkov - check this image: http://www.pearsonified.com/wp-content/uploads/2011/12/font-size-line-height.png
Any chance of someone actually ever looking at this?
A lineHeight property isn't actually supported by apples native UILabel. However the label supports the ability to add an attributedString. For example :
Adding the attributedString like so ,should achieve the desired effect.There should now be a line break of 5 pixels.
@apetkov only for iOS
Guys, I think this ticket should be marked as RESOLVED since we have
lineSpacing
for Android (5.4.0) and Attr Strings for iOSI disagree. Feature parity between platforms is important. It doesn't make sense to have to use completely different elements for each platform to get something as simple as line spacing added. Labels are a very common element and having to swap them out conditionally for each platform dramatically complicates a cross platform code base. Attributed strings are meant for advanced formatting of text. I guess the only other alternative would then be to allow line height to be set on attributed strings on android. But at the moment their is no commonality between platforms which should be fixed.
I disagree too. Attributed strings are far more difficult to use. A simple lineHeight property, just like css, would be a hell easier :-)
Carlos is correct. That's what the
Ti.UI.AttributedString
is meant for and therefore should be used. It is much more configurable with a more advanced API. TIMOB-24080 and the PR by [~kopiro] will add a unified API for iOS and Android, thx!Still awesome to have it as an AttributedString but since I've added
lineSpacing
to the label it's easy to port it to the TextArea: PR: https://github.com/appcelerator/titanium_mobile/pull/8789 Testcode:master: https://github.com/appcelerator/titanium_mobile/pull/9564
FR Passed. Waiting for merge to get enabled.
PR Merged.
Changes are seen in SDK 7.0.0.v20171114202841.