Multiline CATextLayer - objective-c

I'm trying to recreate the multiline UILabel with a CATextlayer.
Is there a property for CATextLayer, or do I need to create it myself?

I'm not sure what you mean exactly, but if you add a CATextLayer to a view, you can set it to have the same bounds as the view and if you enable the wrapped property on the CATextLayer, the text will word wrap. You can then also set the resizing mask on the layer so that changes to the view will be reflected in the layer.

Related

CATextLayer Animate individual characters

I am trying to find an elegant way to animate frame & opacity of individual characters in CATextLayer. However to make the completion of animation smooth I am unable to find a way to determine the position of each character in the text. The text as well are font are dynamic so statically determining kerning or spacing is not possible.
CATextLayer accepts NSAttributedString for string property.
Then, you can try to create multiple same text layers, and set some characters to transparent color.

IOS 7 Approach for create container with two elements?

So, i am new to xcode and iOS7 and i'm trying to create simple container with two elements inside.
I prefer to make it 100% programmatically. (no IB)
I want to create container with two elements Image and Label.
I want to achieve variable width depends on the text element inside.
Here is example:
Based on user action i want to change text on the fly. Let's assume longer text, and main container have to change width too.
And now the question is: What is best approach to to that?
UIView with subviews or something else i'm just expecting direction.
Code examples with be gratefully appreciated.
Thank you in advance.
What you have described is exactly what a UIButton does automatically: it is a container containing an image and a title (text) and it resizes itself automatically when the text changes.
Let us assume, however, that you want to do this yourself. That is, let's say you want a UIView ("container") containing two other UIViews (subviews). Then we need to discuss this requirement:
Based on user action i want to change text on the fly. Let's assume longer text, and main container have to change width too.
This is not going to happen automatically. You can use constraints (auto layout) to describe the size / position of the subviews in relation to the superview, but it works the other way: the superview changes, and the subviews obey. So you will have to change the superview size manually after you change the text.
You can still use auto layout to help you. Let's say the text is in a UILabel. Well, a UILabel wants to change width automatically when the text changes. So far so good. But you must still change the container view width yourself. You can call systemLayoutSizeFittingSize: to learn what the size of the container should be, using constraints, working from the inside out; but then you will have to change its size yourself to that size.
(You can easily create the view, the subviews, and the auto layout constraints in code.)
If you don't want to use autolayout, then you will just calculate the sizes and positions of everything when the text changes and adjust it all yourself (in code). You can learn the size the label needs to be, to fit its text, by calling sizeThatFits: (or sizeToFit which will actually resize it correctly).

Remove UITabBar horizontal separator in iOS7

I want to remove the horizontal separator line between a UITabBar and the rest of the screen. I'm asking the same question as this guy but updated for iOS7.
Setting the background image of my UITabBar doesn't alleviate the problem, nor does setting the background image of the [UITabBar appearance] object.
Is this still possible in iOS7? If so, how?
You could also hide shadow line using this code:
[self.tabBar setValue:#(YES) forKeyPath:#"_hidesShadow"];
Swift
self.tabBar.setValue(true, forKey: "_hidesShadow")
The answer to this is pretty much the same as removing the separator of a navigation bar or a toolbar.
Officially, this is only possible by setting the shadowImage to an empty image. However, a closer look at the documentation, we see that:
For a custom shadow image to be shown, a custom background image must
also be set using the backgroundImage property. If the default
background image is used, then the default shadow image will be used
regardless of the value of this property.
By using a custom background image, you would lose the blurred background translucency.
The separator is a UIImageView that is a subview of the tab bar. You can find it in the tab bar's hierarchy and set it to hidden.
This solution uses a transparent image, so it is more preferable.
Swift
tabBar.shadowImage = UIImage()
Objective-C
tabBar.shadowImage = UIImage.new;

UILabel autoshrink is not working using interface builder?

I made a UILabel and set interface builder properties as
LINES "0"
LINE BREAK "WORD WRAP"
AUTOSHRINK "MINIMUN FONT SIZE"
But whenever a large text is set on label, it does not shrink. Why?
Is there any other thing is needed to be set ?
Auto shrink only works if you have constraints that fix the size of the label.
Either set a fixed "width" constraint on the label, or fix its width relative to its container, by pinning it to the superview.
edit: grammar is hard.

How to cut UIView content?

Please help!!! I am using gesture recognizer to move my UIView. During moving I am changing width of my view, but content become out of borders... How to cut content of view? I need only temporary cut it, not remove, because I need then restore content. Does anybody know the solution?
Set clipsToBounds property of your view to YES (either programmatically or in interface builder).
Normally, a subview’s visibile area is not clipped to the bounds of its superview, but in iOS you can use the clipsToBounds property to alter that behavior.
Try setting
myView.clipsToBounds = YES;