Appcelerator Titanium - Setting a View or Label max height - appcelerator

I have a list with titles coming from data source. The length of the title is unknown and could be one line, two lines and even more... under the title I want to place the name of the author of the post.
I placed the two labels (the title label and the author label inside a View with layout: 'vertical' which places the author label under the title label. But still had to somehow limit the number of rows displayed by the title - I want to have maximum 2 rows. So I've set the height of the subject label.
While setting the height of the label does limit the number of rows displayed, it causes another problem - on rows where the title is 2 lines or more everything looks great. but on rows where the title is only one row, there's now space between that row and the author name - and I want to have the author name right under the label (important thing to notice - the author label has a different font size and color than the title).
If it was just plain old html I would just set max-height css property - but Titanium doesn't have that kind of property on Views/Labels. Is there a way to have maximum height on a View?

There is no such property max-height being supported by Appcelerator for views. But what you can do is, you can listen for the postlayout event for the view and once triggered you can get the rect, to get the height of the view. Now in here you can do your magic. If the height of the view is greater than some value you want, then you can fix it, else let is remain as is.
Do let us know if it works for you. If not, we can try to come up with some other solution.

On Android you can use maxLines on a Label.
For Views and iOS you could do the following. Set the view's height:Ti.UI.SIZE and use bottom to set the minimum space between the views bottom and that of its parent. This only works if the parent has a fixed size.
Listening to post layout on a ListView won't work since you would have to set this on the ListView but don't have a way to access the rect or size property of the ListItem views.

I've just added the numberOfLines in the iOS SDK: https://jira.appcelerator.org/browse/TIMOB-24071
It's called maxLines for Android parity. It really works for Labels inside ListView templates.

Related

What is the name of this macOS UI Control? [duplicate]

I think I must be missing something simple but being new to Xcode... Specifically I am coding in Swift but I believe this is more of a .xib file question. It is easy to have add and delete buttons outside of an NSTableView (like the native Mail app's Preferences->Signatures panel) but how do you integrate these into what seems to be the NSTableView itself? (more like the native Mail app's Preferences->Accounts panel) Ideally I want the option to have more than just add / delete buttons present but once I understand the process adding more functionality should be easy.
These buttons are not integrated, it's just an NSSegmentedControl aligned to the bottom of the table view.
To get this particular appearance of the NSSegmentedControl
Set Style to Small Square
Set Mode to Momentary
Set the Image of Segment 0 to NSAddTemplate
Set the Image of Segment 1 to NSRemoveTemplate
Set the width of Segment 0 and 1 to Auto
Set the width of Segment 2 to a fixed width.
The particular example you showed is just some buttons in a container view abutting the bottom of the scroll view that contains the table view. The container view draws a background to match the buttons and a border. It's probably actually "underlapping" the scroll view by a point so you don't get a doubled border between them.
In fact, if you look carefully, the container view is one point too narrow, so that its right border doesn't match the right border of the scroll view. That kind of proves that it's not part of or in the scroll view.
I also had the same question & I posted an answer here :)
But what I think is its a NSView containing 2 NSButtons for + & - as posted in my answer linked above.

Location of Add/Delete Buttons for an NSTableView in OS X

I think I must be missing something simple but being new to Xcode... Specifically I am coding in Swift but I believe this is more of a .xib file question. It is easy to have add and delete buttons outside of an NSTableView (like the native Mail app's Preferences->Signatures panel) but how do you integrate these into what seems to be the NSTableView itself? (more like the native Mail app's Preferences->Accounts panel) Ideally I want the option to have more than just add / delete buttons present but once I understand the process adding more functionality should be easy.
These buttons are not integrated, it's just an NSSegmentedControl aligned to the bottom of the table view.
To get this particular appearance of the NSSegmentedControl
Set Style to Small Square
Set Mode to Momentary
Set the Image of Segment 0 to NSAddTemplate
Set the Image of Segment 1 to NSRemoveTemplate
Set the width of Segment 0 and 1 to Auto
Set the width of Segment 2 to a fixed width.
The particular example you showed is just some buttons in a container view abutting the bottom of the scroll view that contains the table view. The container view draws a background to match the buttons and a border. It's probably actually "underlapping" the scroll view by a point so you don't get a doubled border between them.
In fact, if you look carefully, the container view is one point too narrow, so that its right border doesn't match the right border of the scroll view. That kind of proves that it's not part of or in the scroll view.
I also had the same question & I posted an answer here :)
But what I think is its a NSView containing 2 NSButtons for + & - as posted in my answer linked above.

Dynamically increasing height of content view of a scroll view in ios9

I am struggling with this stuff for a few days. I am having a view controller in which I have a scroll view and above it a content view. In the content view I am displaying some text from web in a label. I am using a view controller of free form size 600*1000 for my designing purpose.I have given the following constraint to my content view -
1)pinned to the edges of scroll view.
2)content view width equals to superview width.
3)content view height equal to 900.
My scroll view is working perfect.
So now I want that whenever my text increases then my label size would increase thereby increasing the height of my content view automatically. So how to do so. Any answers are most welcome. Thank you.
Set the number of lines for your UILabel to 0.
Add leading, trailing, top and bottom constraints to UILabel.
Set number of lines to 0 does the trick, as the content increases UILabel will automatically adjust the height.

IOS Auto layout not displaying the UILabel in multiple lines when content length is longer

I am trying to build a screen similar to twitter/instagram profile page where there is a header section and below that scrollable content.
I have a view controller which has a table view. I wanted to include a header view on top of the table cells. So i dragged and dropped a "View" just above my cell and it works fine. Now i have a label inside this header view and i want the label height and UI view height to adjust automaticlly based on the content length of the label. (If the content is a long string, the number of lines of label should automatically increase and the container view(headerview)'s height should increased based on it's content items property.
I tried to set auto layout on the table(top left right and bottom to the container view(headerview). But then the label is shown in single line, truncated at the very right corner. If i remove the bottom constraint from my constraints, the label appear in multiple lines, but the container view(headerview)'s height is not increased, thus producing an overlap of the label on top of the table below that.
I have the number of lines property set to 0 for the label.
Can anyone share some ideas how to do this ? I am using Xcode 7 and swift 2
There are several approaches for what you want to accomplish. If you do not care if the header scrolls with the cells, the easiest way is to do something like this:
----------------
Header
Label
TableView
----------------
You should pin your header Top,Right,Left.
You should pin your tableView Right,Bottom,Left.
You should pin Header.bottom = TableView.top.
You should pin your Label 4 sides to it's superview(Header).
Set Label numberOfLines = 0
If your header has a fixed width, the label will automatically inherit that width, and setting numberOfLines=0 (a.k.a unlimited number of lines) will make your label increase it's height. Because your label is pinned to it's superView by it's 4 sides (and the header has no fixed height), your header must increase it's height to match the label height.
Hope it helps!!

NSTableView with Plus and Minus buttons

How can I do something like that?
I didn't find any appropriate object in the Interface Builder library.
Any thoughts?
The best way that i found is to use NSSegmentedControl.
after you dragged it on the canvas, you should configure its style:
Style: Small Square
Mode: Select Momentary
looks better. Now use "image" field to set NSAddTemplate and NSRemoveTemplate. Make sure that label field is empty.
Ok, we have "+", "-" and one empty segment. To prevent the latest one to be selected by the user, select it from Segment: pop up and turn off Enabled check box (located next to State: label).
And lastly, what we have to do is set width of first two segments to make them square.
Go to Size inspector
Select Segment 0
Turn off "Fixed" checkbox (segment should immediately autoresize to fit image)
Select Segment 1 and repeat number 3
Now as you resize control, only last segment will change width
Put it at the bottom of your table view and resize as well.
Enjoy ;)
Update for OSX Yosemite
I tried to achieve the same look as Mail.app has in the Accounts view (right window on my screenshot).
I did achieve the desired result by following the steps below:
Add a NSSegmentedControl
Add two segments and set the image to each:
NSAddTemplate for the + button
NSRemoveTemplate for the - button
Set the size of the segments to fixed and set the value to 32 pixels
The rectangle next to the buttons is a NSButton with the style Gradient.
The Button is enabled but Refuses First Responder is set to true so that it is not clickable.
Use a NSButton with a gradient style, and for the images use the system provided NSAddTemplate and NSRemoveTemplate.
One answer here suggests using gradient buttons, however these buttons cannot be disabled as this causes the background to change and thus breaks the look. Another one suggested using a segmented control, which is almost perfect but segmented controls don't support autoresizing, e.g. if the table width is dynamic. My suggestion is a combination of both. Use a segmented control for the actual buttons and a gradient button to fill the rest of the table width that now can also be dynamic if the button width is dynamic as well.
See my answer to a similar question (with screenshots):
https://stackoverflow.com/a/22586314/15809

Resources