TextView And Its Content - ios

I want to place information text in main scene of the application. When ı place a text view, its content starts at the middle. There is a between the text and top boundary of the TextView.
How can I make the text start at the first line of the TextView ?

You can set the contentOffset property of textView to zero like
textView.setContentOffset(CGPoint.zero, animated: false)

Swift 3
textView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

Related

How to set maximum width of message bubbles in MessageKit

I have been using MessageKit for my live chat feature for my application. One of the issues I am running into is that long messages just look very weird on the screen as the width of the bubbles doesn't seem to be restricted. I wanted to figure out a way to be able to set the maximum width of the chat bubbles so that they format more like a text conversation on the native imessage application.
Currently my messages look like this, but I would want the message below to be less wide and taller:
You can adjust the right/left padding for incoming/outgoing messages respectively.
The default padding is:
public var incomingMessagePadding = UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 30)
public var outgoingMessagePadding = UIEdgeInsets(top: 0, left: 30, bottom: 0, right: 4)
And you can set the padding on the layout object in your messages view controller like this:
let layout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout
layout?.setMessageIncomingMessagePadding(UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 50))
layout?.setMessageOutgoingMessagePadding(UIEdgeInsets(top: 0, left: 60, bottom: 0, right: 4))
You can see more examples of layout changes in the AdvancedExampleViewController in the MessageKit example project.
It seems that the library that you are using has already a width set, but in my chat (which is customised) I have a greater than or equal than 0 width constraint a a less than or equal than MAX_WIDTH constraint a leading constraint = 0 and a 'trailing constraint = 0' and those last two I get rid of the leading or trailing depending on if it is the sender or receiver of the message.

UITableView Separator Inset Reference not working in storyboard

I want to inset the table view separator by 10 points from the current automatic inset so it respects the safe area etc. but when I set it in the storyboard it doesn't work as documented.
Turns out the settings in the storyboard are not being respected.
When I added the settings in code then it worked as expected.
tableView.separatorInsetReference = .fromAutomaticInsets
tableView.separatorInset = .init(top: 0, left: 10, bottom: 0, right: 0)

ios scrollIndicatorInsets won't go beyond scrollview bounds

I want to put scrollViewIndicator just a bit more outside(right) of scrollView. But It doesn't go even if I set self.mainMenuCollectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 10, 0, 0);. It might because of inset works as padding and not going out of bounds of scrollView. It stays in the border.
It works for putting indise(left) of the view.
It would be really helpful if you know how can I achieve that.
N: normal
S: It is possible
W: How I want
You need to setup opposite side with minus sign like:
self.mainMenuCollectionView.scrollIndicatorInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: -10)
Don't forget disable clipsToBounds for getting visible subviews outside:
self.mainMenuCollectionView.clipsToBounds = false

add cells in UICollectionView from bottom to top using Swift 4.2

I'm trying to implement a Chat screen using UICollectionView in Swift 4.2. I've done it.
I want to improve it by making the cells grow from bottom to top instead of top to bottom (while keeping the order of messages too). Any help? I've tried searching for it, still unsuccessful.
The easiest way would be to flip the collection view and its cells:-
cv.transform = CGAffineTransform(scaleX: 1, y: -1)
cell.contentView.transform = CGAffineTransform(scaleX: 1, y: -1)
Doing this will just flip your CollectionView's content and won't require you to handle anything, I guess
EDIT:-
For your requirement, you shouldn't be appending elements to your array. You should insert new objects as the first element of the array(the data source):-
myArray.insert(element, at: 0)
In order to get the right order, you can just reverse the array
You have to make collection view height constraint outlet for it and calculate your cells height after that you can set height of collectionView. and one case will come of maximum height, your collection height will equal from screen height with calculate space your navigation and input textview.
Have you tried
let diff = collectionView.frame.height - collectionView.contentSize.height
if diff > 0 {
collectionView.contentInset = UIEdgeInsets(top: diff, left: 0, bottom: 0, right: 0)
}
You can modify the top inset of the collection view as the collectionView reloads.
Call this after calling reloadData():
func updateCollectionContentInset() {
let contentSize = yourCollectionView.collectionViewLayout.collectionViewContentSize
var contentInsetTop = yourCollectionView.bounds.size.height
contentInsetTop -= contentSize.height
if contentInsetTop <= 0 {
contentInsetTop = 0
}
yourCollectionView.contentInset = UIEdgeInsets(top: contentInsetTop,left: 0,bottom: 0,right: 0)
}

Is it possible to animate UIEdgeInsets?

I've been trying to animate a change in UIEdgeInsets. I've already tried using UIView.animateWithDuration and the insets just jump to the final values. Does anyone know if this a property that can't be animated? Or better yet, is anyone aware of a way to animate insets?
As an example:
// Starting inset values
self.searchField.placeHolderInset = UIEdgeInsets(top: 0, left: 110, bottom: 0, right: 10)
// Animation block
UIView.animateWithDuration(0.1, animations: {
self.searchField.placeHolderInset = UIEdgeInsets(top: 0, left: 18, bottom: 0, right: 10)
})
Instead of moving 92 pixels to the left over 0.1 seconds, the text jumps to the final value. searchField is a UITextField and .placeHolderInset is the UIEdgeInset being used to determine the insets for the UITextField's placeholder text.
EDIT: Another way to achieve the desired effect is by changing the UITextField's .textAlignment from .Center to .Left but that won't animate either.
You need to call layoutIfNeeded() on the view, inside of the animation block.

Resources