Animate NSTextField Alignment - objective-c

I'm trying to emulate the functionality of the Safari url text field (using NSTextField). I'd like the current text to be displayed centered, but when the user clicks on it the text should highlight and slide to the left. I've got the highlighting working but I'm not sure how to go about animating the text over to the left. Is it possible to animate the Alignment property or would I need to do some sort of custom drawing where I animate the position that the text is drawn?
Unfortunately this (Is there a way to animate changing a UILabel's textAlignment?) won't work, since a text field draws a background and border so animating the frame isn't an option.

Related

OS X chat app with resizable bubbles

I'm building chat application for Mac OS, similar to iMessage. I wonder, how can I implement resizable text views in bubbles. I mean, when I resize chat window bubbles with text will resize to. Any ideas, links will be very useful. Thank you for help)
For text resizing, you use auto layout. If you have an NSScrollView containing MYBubbleViews containing NSTextViews, you can add NSLayoutConstraints using the leftAnchor and rightAnchor properties of the scroll view's content view and those of the bubble view, and add constraints between all edges of the text view and bubble view. Then pin the bubble views to the top/prev view.
Also make sure you set the NSTextView to wrap. The width of the intrinsic size of the text view will be set so that it fills the width and the intrinsic height will be set to fit the whole text.
I previously thought it was about drawing the bubbles, so I first gave this answer:
If you look at Messages.app, you'll see that they're not circular bubbles. They are basically composed of several shapes overlaid on each other. A rectangle with rounded corners, plus a bezier path of the tip.
So you should be able to take a NSTextView for the text, make it a subview of a custom view that draws a rounded rectangle and the tip in its drawRect method, and then use auto layout constraints to make your bubble view resize with the text view and the text view to the window width.
You could probably also have the bubble view host a CALayer with fill and rounded corners, plus one with an image for the tip (or aCAShapeLayer for the tip), but drawRect is the easier approach.

How to align the bottom of a UIView with the bottom of the screen always

I want a background image to always be aligned with the bottom of the screen regardless of screen size, iOS Version, or Personal Hotspot messages etc. But none of the interface builder alignment options seem to work in every case.
I have 2 different sized images to fit 3.5' and 4' retina which change via code but their alignment is always thrown off by 'Personal Hotspot' and other messages changing the size of the parent view.
My images are the size of the screen and should fill the whole screen always. There is a black area where tab bar and status bar will overlay.
There are buttons aligned with the background and everything gets thrown out by messages that resize the parent view.
I want the bottom of the UIImageView to be aligned with the bottom of the screen always.
have you tried the contentMode property?
theImageView.contentMode = UIViewContentModeBottom;
There is also a menu item for this in interface builder if you prefer to set it there.
then if you are using auto layout, simply add a bottom space constraint from your image view to the bottom layout guide.
If you're not using auto layout, a fixed bottom margin on the autoresizing mask should do the trick.

Resize buttons styled with AppBarButtonStyle

I like the AppBarButtonStyle idea of using font character as button icon because of its scaling abilities, but it is of no use if i cannot resize them properly.
Changing Width or Height of button does not work, because AppBarButtonStyle only resizes padding between button icon and button borders. Changing FontSize of button does not work either.
Is there any way of resizing buttons styled with AppBarButtonStyle in WinRT application? I dont mind if i have to override or modify AppBarButtonStyle, as long as it preserves the ability to use font character as button icon.
Any useful advices will be appreciated!
You can easily create your own custom button from AppBarButtonStyle from the original in the standardstyles.xaml .
I did so to create a custom smaller button with no text and the only hard part was aligning everything: you're not adding shapes, you're adding a character, so it may not be as aligned as you think. Default Buttons contain 3 charatctes: outline, fill and glyph.
If you want, I can share my simplified code for the control.

scrollbar contentsize change when keyboard appears

I have a view controller with a scrollview with lots of text boxes, when i click on one of the text boxes and the keyboard appears, the content size of the scrollview isn't long enough to show everything with the keyboard open. How can i change the content size every time the keyboard pops up and set it back once it vanishes?
Also is there a method to make it vanish without resignfirstresponder on every textfield?
Hope someone can help me, I'm pretty new to Objective C.
contentSize probably isn't the property you should be changing.
Try changing the frame property of the scroll view (i.e. make it n pt smaller, where n is the height of the keyboard - 216 in portrait, 162 in landscape.)
The scroll view should deal with letting your content scroll correctly after you've changed it's frame.
The content size property is the size of the thing that is being scrolled - this doesn't change, it's just the amount that you can see that has changed.
(If you're feeling flash, you can animate the change in height of the frame :)

Getting viewable text position after scroll a UITextView

I have a UITextView and a slide control. The text view has a long content to read. I can drag slide to move text view text to corresponding percentage now. But I want to move slide to corresponding position by scroll text view. I can use an inherit UITextView to catch event. But how I can get current viewable text position?