TextField Corner Radius : Not Sharp Corners - ios

I am trying to add corner radius on uitextfield effect applies but not sharp corner.
Please check attached pictures.
I am expecting result like this.
Here is my Code for gray textfield.
self.layer.cornerRadius = 7.5
self.layer.borderWidth = 1.5
self.layer.borderColor = UIColor(red: 209/255.0, green: 209/255.0, blue: 209/255.0, alpha: 1.0).CGColor
self.backgroundColor = UIColor.whiteColor()
Here is my Code for Red textfield.
self.layer.cornerRadius = 7.5
self.layer.borderWidth = 1.5
self.layer.borderColor = TextFieldRedBorderColor.CGColor
self.backgroundColor = TextFieldRedBackgroundColor
There is only color difference between both code but still it's not working.

self.layer.masksToBounds = true
This will solves your issue

#IBOutlet var passwordboarderview: UIView!
#IBOutlet var textusername: UITextField!
#IBOutlet var txtpassword: UITextField!
passwordboarderview.layer.cornerRadius = 7.5
passwordboarderview.layer.borderColor = UIColor.whiteColor().CGColor
passwordboarderview.layer.borderWidth = 2.0
passwordboarderview.clipsToBounds = true
txtpassword.attributedPlaceholder = NSAttributedString(string:"Password",attributes:[NSForegroundColorAttributeName: UIColor.whiteColor()])
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
textusername.leftView = paddingView
textusername.leftViewMode = .Always
textusername.layer.borderWidth = 2.0
textusername.layer.cornerRadius = 7.5
textusername.layer.borderColor = UIColor.grayColor().CGColor
textusername.clipsToBounds = true
Output :
Storyboard:

//
// FDTextField.swift
// FilloutDocs
//
// Created by Janak Thakkar on 15/03/16.
// Copyright © 2016 zetrixweb. All rights reserved.
//
import UIKit
private var maxLengthDictionary = [UITextField : Int]()
#IBDesignable
class ZWTextField : UITextField {
var topBorder: UIView?
var bottomBorder: UIView?
var leftBorder: UIView?
var rightBorder: UIView?
var leftimageview : UIImageView?
var rightimageview : UIImageView?
#IBInspectable var borderColor: UIColor = UIColor.clearColor() {
didSet {
layer.borderColor = borderColor.CGColor
}
}
#IBInspectable var ULText: Bool = false {
didSet {
let textRange = NSMakeRange(0, (self.text?.characters.count)!)
let attributedText = NSMutableAttributedString(string: (self.text)!)
attributedText.addAttribute(NSUnderlineStyleAttributeName , value:NSUnderlineStyle.StyleSingle.rawValue, range: textRange)
// Add other attributes if needed
self.attributedText = attributedText
}
}
#IBInspectable var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth
}
}
#IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
}
}
#IBInspectable var fitToWidth: Bool = false {
didSet {
adjustsFontSizeToFitWidth = fitToWidth
}
}
#IBInspectable var cursorColor : UIColor = UIColor.blueColor(){
didSet {
tintColor = cursorColor
}
}
#IBInspectable var placeHolderColor : UIColor = UIColor.lightGrayColor(){
didSet {
setValue(placeHolderColor, forKeyPath: "_placeholderLabel.textColor")
}
}
override func layoutSubviews() {
super.layoutSubviews()
}
#IBInspectable var rightImage : UIImage? {
didSet {
if rightImage != nil {
let width = rightviewWidth > rightImage!.size.width + 10 ? rightviewWidth : rightImage!.size.width + 10
rightViewMode = UITextFieldViewMode.Always
rightimageview = UIImageView()
rightimageview!.frame=CGRectMake(self.frame.size.width - width, self.frame.origin.y+2, width,self.frame.size.height-4)
rightimageview!.image = rightImage
rightView = rightimageview
self.rightViewMode = .Always
rightimageview!.contentMode = .Center
}
else {
if rightimageview != nil {
rightimageview?.removeFromSuperview()
rightimageview = nil
}
}
}
}
#IBInspectable var rightviewWidth : CGFloat = 0 {
didSet{
if rightimageview != nil{
let width = rightviewWidth > rightImage!.size.width + 10 ? rightviewWidth : rightImage!.size.width + 10
rightimageview!.frame=CGRectMake(self.frame.origin.x+5, self.frame.origin.y+2, width,self.frame.size.height-4)
}
}
}
#IBInspectable var leftImage : UIImage? {
didSet {
if leftImage != nil {
let width = leftviewWidth > leftImage!.size.width + 10 ? leftviewWidth : leftImage!.size.width + 10
leftViewMode = UITextFieldViewMode.Always
leftimageview = UIImageView();
leftimageview!.frame=CGRectMake(self.frame.origin.x+50, self.frame.origin.y+5, width,self.frame.size.height-5)
//leftimageview!.frame = CGRectMake(10, 5, 40, 40)
leftimageview!.image = leftImage;
leftView = leftimageview;
self.leftViewMode = .Always
leftimageview!.contentMode = .Center
}
}
}
#IBInspectable var leftviewWidth : CGFloat = 0 {
didSet{
if leftimageview != nil{
let width = leftviewWidth > leftImage!.size.width + 10 ? leftviewWidth : leftImage!.size.width + 10
leftimageview!.frame=CGRectMake(self.frame.origin.x+5, self.frame.origin.y+2, width,self.frame.size.height-4)
}
}
}
#IBInspectable var bottomLineWidth : CGFloat = 1 {
didSet{
let border: CALayer = CALayer()
border.borderColor = UIColor.darkGrayColor().CGColor
self.frame = CGRectMake(0, self.frame.size.height - bottomLineWidth, self.frame.size.width, self.frame.size.height)
border.borderWidth = borderWidth
self.layer.addSublayer(border)
self.layer.masksToBounds = true
}
}
#IBInspectable var bottomLineColor : UIColor = UIColor.lightGrayColor(){
didSet {
let border: CALayer = CALayer()
border.borderColor = bottomLineColor.CGColor
}
}
#IBInspectable var paddingLeft: CGFloat = 0
#IBInspectable var paddingRight: CGFloat = 0
override func textRectForBounds(bounds: CGRect) -> CGRect {
return CGRectMake(bounds.origin.x + paddingLeft, bounds.origin.y,
bounds.size.width - paddingLeft - paddingRight, bounds.size.height);
}
override func editingRectForBounds(bounds: CGRect) -> CGRect {
return textRectForBounds(bounds)
}
#IBInspectable var topBorderColor : UIColor = UIColor.clearColor()
#IBInspectable var topBorderHeight : CGFloat = 0 {
didSet{
if topBorder == nil{
topBorder = UIView()
topBorder?.backgroundColor=topBorderColor;
topBorder?.frame = CGRectMake(0, 0, self.frame.size.width, topBorderHeight)
addSubview(topBorder!)
}
}
}
#IBInspectable var bottomBorderColor : UIColor = UIColor.clearColor()
#IBInspectable var bottomBorderHeight : CGFloat = 0 {
didSet{
if bottomBorder == nil{
bottomBorder = UIView()
bottomBorder?.backgroundColor=bottomBorderColor;
bottomBorder?.frame = CGRectMake(0, self.frame.size.height - bottomBorderHeight, self.frame.size.width, bottomBorderHeight)
addSubview(bottomBorder!)
}
}
}
#IBInspectable var leftBorderColor : UIColor = UIColor.clearColor()
#IBInspectable var leftBorderHeight : CGFloat = 0 {
didSet{
if leftBorder == nil{
leftBorder = UIView()
leftBorder?.backgroundColor=leftBorderColor;
leftBorder?.frame = CGRectMake(0, 0, leftBorderHeight, self.frame.size.height)
addSubview(leftBorder!)
}
}
}
#IBInspectable var rightBorderColor : UIColor = UIColor.clearColor()
#IBInspectable var rightBorderHeight : CGFloat = 0 {
didSet{
if rightBorder == nil{
rightBorder = UIView()
rightBorder?.backgroundColor=topBorderColor;
rightBorder?.frame = CGRectMake(self.frame.size.width - rightBorderHeight, 0, rightBorderHeight, self.frame.size.height)
addSubview(rightBorder!)
}
}
}
#IBInspectable var maxLength: Int {
get {
if let length = maxLengthDictionary[self] {
return length
} else {
return Int.max
}
}
set {
maxLengthDictionary[self] = newValue
addTarget(self, action: "checkMaxLength:", forControlEvents: UIControlEvents.EditingChanged)
}
}
func checkMaxLength(sender: UITextField) {
let newText = sender.text
if newText?.characters.count > maxLength {
let cursorPosition = selectedTextRange
text = (newText! as NSString).substringWithRange(NSRange(location: 0, length: maxLength))
selectedTextRange = cursorPosition
}
}
}
Just add this file in project and you can set all the properties and can see realtime out.All properties you can set through storyboard.

There was just one mistake in my code.
TextField Border Style Was Line
textField.borderStyle = .Line
then I make it None
textField.borderStyle = .None
and it work like I wanted (Rounded Corners)...
Anyway.. Thanks for support and answers...

Related

IOS Step menu using swift

I would like to create the stepper menu in IOS using swift, But I'm facing some issues. Here are the issues.
1) Portrait and landscape stepper menu is not propper.
2) How to set default step position with the method below method, It's working when button clicked. But I want to set when menu loads the first time.
self.stepView.setSelectedPosition(index: 2)
3) If it reached the position last, I would like to change the color for complete path parentPathRect.
4) Progress animation CABasicAnimation is not like the progress bar, I want to show the animation.
5) It should not remove the selected position color when changing the orientation.
As per my organization rules should not use third-party frameworks.
Can anyone help me with the solution? Or is there any alternative solution for this?
Here is my code:
import UIKit
class ViewController: UIViewController, StepMenuDelegate {
#IBOutlet weak var stepView: StepView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.stepView.delegate = self;
self.stepView.titles = ["1", "2", "3"]
self.stepView.lineWidth = 8
self.stepView.offSet = 8
self.stepView.setSelectedPosition(index: 2)
}
func didSelectItem(atIndex index: NSInteger) {
print(index)
}
}
protocol StepMenuDelegate {
func didSelectItem(atIndex index: NSInteger)
}
class StepView: UIView {
var delegate : StepMenuDelegate!
var titles: [String] = [] {
didSet(values) {
setup()
setupItems()
}
}
var lineWidth: CGFloat = 8 {
didSet(values) {
setup()
}
}
var offSet: CGFloat = 8 {
didSet(values) {
self.itemOffset = offSet * 4
setup()
}
}
private var selectedIndex : NSInteger!
private var itemOffset : CGFloat = 8 {
didSet (value) {
setup()
setupItems()
}
}
private var path : UIBezierPath!
var selectedLayer : CAShapeLayer!
private var parentPathRect : CGRect!
override func awakeFromNib() {
super.awakeFromNib()
}
override func layoutSubviews() {
self.setup()
setupItems()
}
func setup() {
self.removeAllButtonsAndLayes()
let layer = CAShapeLayer()
self.parentPathRect = CGRect(origin: CGPoint(x: offSet, y: self.bounds.midY - (self.lineWidth/2) ), size: CGSize(width: self.bounds.width - (offSet * 2), height: lineWidth))
path = UIBezierPath(roundedRect: self.parentPathRect, cornerRadius: 2)
layer.path = path.cgPath
layer.fillColor = UIColor.orange.cgColor
layer.lineCap = .butt
layer.shadowColor = UIColor.darkGray.cgColor
layer.shadowOffset = CGSize(width: 1, height: 2)
layer.shadowOpacity = 0.1
layer.shadowRadius = 2
self.layer.addSublayer(layer)
}
func setupItems() {
removeAllButtonsAndLayes()
let itemRect = CGRect(x: self.itemOffset, y: 0, width: 34, height: 34)
let totalWidth = self.bounds.width
let itemWidth = totalWidth / CGFloat(self.titles.count);
for i in 0..<self.titles.count {
let button = UIButton()
var xPos: CGFloat = itemOffset
self.addSubview(button)
xPos += (CGFloat(i) * itemWidth);
xPos += itemOffset/3
button.translatesAutoresizingMaskIntoConstraints = false
button.leftAnchor.constraint(equalTo: self.leftAnchor, constant: xPos).isActive = true
button.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: 0).isActive = true
button.heightAnchor.constraint(equalToConstant: itemRect.height).isActive = true
button.widthAnchor.constraint(equalToConstant: itemRect.width).isActive = true
button.backgroundColor = UIColor.red
button.layer.zPosition = 1
button.layer.cornerRadius = itemRect.height/2
let name : String = self.titles[i]
button.tag = i
button.setTitle(name, for: .normal)
button.addTarget(self, action: #selector(selectedItemEvent(sender:)), for: .touchUpInside)
if self.selectedIndex != nil {
if button.tag == self.selectedIndex {
selectedItemEvent(sender: button)
}
}
}
}
#objc func selectedItemEvent(sender:UIButton) {
if self.selectedLayer != nil {
selectedLayer.removeFromSuperlayer()
}
self.delegate.didSelectItem(atIndex: sender.tag)
let fromRect = self.parentPathRect.origin
self.selectedLayer = CAShapeLayer()
let rect = CGRect(origin: fromRect, size: CGSize(width:sender.frame.origin.x - 4, height: 8))
let path = UIBezierPath(roundedRect: rect, cornerRadius: 4)
self.selectedLayer.path = path.cgPath
self.selectedLayer.lineCap = .round
self.selectedLayer.fillColor = UIColor.orange.cgColor
let animation = CABasicAnimation(keyPath: "fillColor")
animation.toValue = UIColor.blue.cgColor
animation.duration = 0.2
animation.fillMode = .forwards
animation.isRemovedOnCompletion = false
self.selectedLayer.add(animation, forKey: "fillColor")
self.layer.addSublayer(self.selectedLayer)
}
func removeAllButtonsAndLayes() {
for button in self.subviews {
if button is UIButton {
button.removeFromSuperview()
}
}
}
func setSelectedPosition(index:NSInteger) {
self.selectedIndex = index
}
}
Here I found One way to achieve the solution.!!
https://gist.github.com/DamodarGit/7f0f484708f60c996772ae28e5e1c615
Welcome to suggestions or code changes.!!

ios- UIButton not work in the custom view(UIViewX)

I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this.
create a UIViewX in the View Controller or
add UIButton on custom view(UIViewX). And IBAction is print(" test ")
Everything work good.
But...
When add UIButton on custom view(UIViewX) and add animation code with UIViewX, button does't work if I press it
how to fix it that can response print(" test ")?
Thanks in advance.
Here is animation code :
var currentColorArrayIndex = -1
var colorArray:[(color1: UIColor, color2: UIColor)] = []
override func viewDidLoad() {
super.viewDidLoad()
colorArrayFunction()
backgroundAnimate()
}
colorArrayFunction & backgroundAnimate
Here is UIViewX code :
import UIKit
#IBDesignable
class UIViewXXXXX: UIView {
// MARK: - Gradient
#IBInspectable var firstColor: UIColor = UIColor.white {
didSet {
updateView()}}
#IBInspectable var secondColor: UIColor = UIColor.white {
didSet {
updateView()}}
#IBInspectable var horizontalGradient: Bool = false {
didSet {
updateView()}}
override class var layerClass: AnyClass {
get {
return CAGradientLayer.self}}
func updateView() {
let layer = self.layer as! CAGradientLayer
layer.colors = [ firstColor.cgColor, secondColor.cgColor ]
if (horizontalGradient) {
layer.startPoint = CGPoint(x: 0.0, y: 0.5)
layer.endPoint = CGPoint(x: 1.0, y: 0.5)
} else {
layer.startPoint = CGPoint(x: 0, y: 0)
layer.endPoint = CGPoint(x: 0, y: 1)
}}
// MARK: - Border
#IBInspectable public var borderColor: UIColor = UIColor.clear {
didSet {
layer.borderColor = borderColor.cgColor}}
#IBInspectable public var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth}}
#IBInspectable public var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
}
}
// MARK: - Shadow
#IBInspectable public var shadowOpacity: CGFloat = 0 {
didSet {
layer.shadowOpacity = Float(shadowOpacity)}}
#IBInspectable public var shadowColor: UIColor = UIColor.clear {
didSet {
layer.shadowColor = shadowColor.cgColor}}
#IBInspectable public var shadowRadius: CGFloat = 0 {
didSet {
layer.shadowRadius = shadowRadius}}
#IBInspectable public var shadowOffsetY: CGFloat = 0 {
didSet {
layer.shadowOffset.height = shadowOffsetY}}}

How to marquee UITextField placeholder if text longer then the UITextField width?

Is it possible to marquee UITextFiled placeholder, if placeholder text is longer then the size of UITextField width, There are lib for UILabel MarqueeLabel but I am not sure how to marquee placeholder, please provide some suggestion, Or you can explain what is a placeholder is actually, it doesn't look like UILabel
I am using bellow code for CustomTextField with validation error message
import UIKit
#IBDesignable
class CustomTextField: UITextField {
var placeholdertext: String?
#IBInspectable
public var cornerRadius :CGFloat {
set { layer.cornerRadius = newValue }
get {
return layer.cornerRadius
}
}
// Provides left padding for images
override func leftViewRect(forBounds bounds: CGRect) -> CGRect {
var textRect = super.leftViewRect(forBounds: bounds)
textRect.origin.x += leftPadding
return textRect
}
override func rightViewRect(forBounds bounds: CGRect) -> CGRect {
var textRect = super.rightViewRect(forBounds: bounds)
textRect.origin.x -= rightPadding
return textRect
}
#IBInspectable var leftImage: UIImage? {
didSet {
updateView()
}
}
#IBInspectable var isUnderLine:Bool = false
{
didSet{
updateView()
}
}
#IBInspectable var rightImage: UIImage? {
didSet {
updateView()
}
}
func setError(error:String?){
if(error != nil)
{
self.attributedPlaceholder = NSAttributedString(string: error!, attributes: [NSForegroundColorAttributeName: UIColor.red])
}
}
#IBInspectable var leftPadding: CGFloat = 0
#IBInspectable var rightPadding: CGFloat = 0
#IBInspectable var textLeftPadding:CGFloat = 0
#IBInspectable var color: UIColor = UIColor.lightGray {
didSet {
updateView()
}
}
#IBInspectable var underlineColor:UIColor = UIColor.black
{
didSet{
self.updateView()
}
}
private var placeholderColorValue:UIColor = UIColor.lightGray
#IBInspectable public var placeholderColor:UIColor
{
set{
self.attributedPlaceholder = NSAttributedString(string:placeholder!, attributes: [NSForegroundColorAttributeName: newValue])
placeholderColorValue = newValue
}
get{
return placeholderColorValue
}
}
override init(frame: CGRect) {
super.init(frame: frame)
self.setUpView()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func awakeFromNib() {
super.awakeFromNib()
self.setUpView()
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
}
func setUpView() {
if(rightImage != nil)
{
self.leftViewMode = UITextFieldViewMode.always
let rightImageView:UIImageView = UIImageView(image: rightImage)
rightImageView.frame = CGRect(x: 0, y: 0, width: self.frame.size.height, height: self.frame.size.height)
self.rightView = rightImageView
}
else {
rightViewMode = UITextFieldViewMode.never
rightView = nil
}
}
func updateView() {
if let imageLeft = leftImage {
leftViewMode = UITextFieldViewMode.always
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
imageView.image = imageLeft
// Note: In order for your image to use the tint color, you have to select the image in the Assets.xcassets and change the "Render As" property to "Template Image".
imageView.tintColor = color
leftView = imageView
} else {
leftViewMode = UITextFieldViewMode.never
leftView = nil
}
if let imageRight = rightImage {
rightViewMode = UITextFieldViewMode.always
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
imageView.image = imageRight
// Note: In order for your image to use the tint color, you have to select the image in the Assets.xcassets and change the "Render As" property to "Template Image".
imageView.tintColor = color
rightView = imageView
} else {
rightViewMode = UITextFieldViewMode.never
rightView = nil
}
// Placeholder text color
attributedPlaceholder = NSAttributedString(string: placeholder != nil ? placeholder! : "", attributes:[NSForegroundColorAttributeName: color])
if(self.isUnderLine)
{
let underline:UIView = UIView()
underline.frame = CGRect(x: 0, y: self.frame.size.height-1, width: self.frame.size.width, height: 1)
underline.backgroundColor = underlineColor
self.addSubview(underline)
}
}
override func textRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(x: textLeftPadding, y: 0, width: bounds.width, height: bounds.height)
}
override func editingRect(forBounds bounds: CGRect) -> CGRect {
return self.textRect(forBounds: bounds)
}
}
and using validation as
if (txtField.text != "condtion" ){
txtField.setError(error:"Error message for text field");
valid = false;
txtField.becomeFirstResponder()
}

searchcontroller, roundedcorners not working

This view's order is like this
-View Controller
-Fake shadow view
-Container view
-Search Bar
In normal state, roundedcorner works correctly, but when I click on it, there is some shadow. When I type something on it just the view becomes rectengular
try this IBDesignable class and give rounded corner from story board
import Foundation
#IBDesignable class customView: UIView {
#IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
}
}
#IBInspectable var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth
}
}
#IBInspectable var borderColor: UIColor = UIColor.gray {
didSet {
layer.borderColor = borderColor.cgColor
}
}
#IBInspectable var shadowColor: UIColor = UIColor.gray {
didSet {
layer.shadowColor = shadowColor.cgColor
}
}
#IBInspectable var shadowOpacity: Float = 1.0 {
didSet {
layer.shadowOpacity = shadowOpacity
}
}
#IBInspectable var shadowRadius: CGFloat = 1.0 {
didSet {
layer.shadowRadius = shadowRadius
}
}
#IBInspectable var masksToBounds: Bool = true {
didSet {
layer.masksToBounds = masksToBounds
}
}
#IBInspectable var shadowOffset: CGSize = CGSize(width: 12, height: 12) {
didSet {
layer.shadowOffset = shadowOffset
}
}
}

change inputAccessoryView's height issue in iOS 8.4

I made a MessageComposerView like this
import UIKit
protocol MessageComposerDelegate: NSObjectProtocol {
func messageDidChange(messageView: MessageComposerView, height: CGFloat)
func postMessage(message: String)
}
private let maxTextViewHeight: CGFloat = 100.0
class MessageComposerView: UIView, UITextViewDelegate {
#IBOutlet weak var textView: SAMTextView!
#IBOutlet weak var sendButton: UIButton!
weak var delegate:MessageComposerDelegate?
#IBAction func sendButtonAction(sender: UIButton) {
delegate?.postMessage(textView.text)
}
override func awakeFromNib() {
let borderColor = UIColor(white: 0.9, alpha: 1).CGColor
let layer = CALayer()
layer.backgroundColor = borderColor
layer.frame = CGRectMake(0, 0, CGRectGetWidth(UIScreen.mainScreen().bounds), 1.0)
self.layer.addSublayer(layer)
textView.backgroundColor = UIColor.whiteColor()
textView.layer.borderColor = borderColor
textView.layer.borderWidth = 1.0
textView.layer.cornerRadius = 5.0
textView.delegate = self
textView.layoutManager.allowsNonContiguousLayout = false
sendButton.backgroundColor = Color.Red.colorValue
sendButton.tintColor = UIColor.whiteColor()
sendButton.layer.cornerRadius = 5.0
}
//MARK: TextViewDelegate
func textViewDidChange(textView: UITextView) {
self.sendButton.enabled = !self.textView.text!.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()).isEmpty
textView.scrollEnabled = textView.contentSize.height >= maxTextViewHeight
let height = textView.scrollEnabled ? textView.contentSize.height : textView.intrinsicContentSize().height
delegate?.messageDidChange(self, height: min(height, maxTextViewHeight) + 16.0)
if let selectedTextRange = self.textView.selectedTextRange {
let caretRect = self.textView.caretRectForPosition(selectedTextRange.end);
let height = self.textView.textContainerInset.bottom + caretRect.size.height
self.textView.scrollRectToVisible(CGRectMake(caretRect.origin.x, caretRect.origin.y, caretRect.size.width, height), animated: true)
}
}
}
and in the ViewController when I increase the height of MessageComposerView:
func messageDidChange(messageView: MessageComposerView, height: CGFloat) {
messageView.bounds.size.height = height
self.reloadInputViews()
messageView.textView.reloadInputViews()
}
In iOS 9,It works well.
but in iOS 8.4,The textView and Button not change their frame rightly
So What should I do to fix it in iOS 8.4,Thank you!

Resources