UILabel cannot show its all letters - ios

UILabel cannot show its all letters.
My app is like now my app
PhotoController (it is for this page)is
import Foundation
import MobileCoreServices
import UIKit
class PhotoController:UIViewController,UINavigationControllerDelegate,UIImagePickerControllerDelegate{
#IBOutlet weak var label: UILabel!
#IBOutlet weak var myImageView: UIImageView!
private var imagePicker:UIImagePickerController!
override func viewDidLoad() {
super.viewDidLoad()
label.text = "Tap the PhotoSelect or Camera to upload a picture"
//myImageUploadRequest()
}
So,all letter of
label.text = "Tap the PhotoSelect or Camera to upload a picture"
is not shown in my app.
What should I do to fix this?

label.numberOfLines = 0
Thats all you need :)
EDIT:
Setting line break modes to the label will help you get further improved O/P
label.lineBreakMode = .byWordWrapping //choose whichever matches ur requirement

label.numberOfLines = 0
Either make your label multi line or
label.adjustsFontSizeToFitWidth = true
label.minimumScaleFactor = 0.5

from storyboard
Constraints :
Give constant label height with relationship >=
Property
set number of lines = 0

Related

How to use "MDCOutlinedTextField" in Swift

I need textfield like below image
so i am using material-components-ios framework, for that i have added textfield in storyboard and given its class name to MDCTextField and code
import UIKit
import MaterialComponents
class LoginVC: UIViewController {
#IBOutlet weak var emailTF: MDCTextField!
var textFieldControllerFloating: MDCTextInputControllerOutlined?
override func viewDidLoad() {
super.viewDidLoad()
// setupEditText()
textFieldControllerFloating = MDCTextInputControllerOutlined(textInput: emailTF)
textFieldControllerFloating?.activeColor = UIColor.lightGray
textFieldControllerFloating?.floatingPlaceholderActiveColor = UIColor.green
textFieldControllerFloating?.normalColor = UIColor.lightGray
textFieldControllerFloating?.inlinePlaceholderColor = UIColor.lightGray
}
with this code o/p coming perfect but showing warning
warning:
'MDCTextField' is deprecated: MDCTextField and its associated classes are deprecated. Please use TextControls instead.
so i have added another framework TextControls here i have added pod 'MaterialComponents/TextControls+OutlinedTextFields' and added textfield in stroyboard and given its class to MDCOutlinedTextField and added below code
import UIKit
import MaterialComponents.MaterialTextControls_OutlinedTextFields
class LoginVC: UIViewController {
#IBOutlet weak var emailTF: MDCOutlinedTextField!
#IBOutlet weak var passwordTF: MDCOutlinedTextField!
}
}
but o/p like below: no floating placeholder text and small height as well why?, where am i wrong.. how to get textfield with height 50 and floating placeholder border like above image, please do help.
EDIT: i need eye button for password textfield like this how to do with MDCOutlinedTextField?
As per example try to set label.text property like that
textField.label.text = "Phone number"
As for text field height you can set it for instance with a constraint in Interface Builder

Strange behaviour with monospaced font in UILabel when changing text

I have a strange issue when using monospacedDigitSystemFont(ofSize:weight:)
I have one UISlider and one UILabel in my UIViewController. The Label is showing the current value of the slider + some description text. When changing the slider's value, the text of myLabel is shaking left and right a bit. I would expect the myLabel's text to not shake left and right, since I am using monospacedDigitSystemFont(ofSize:weight:).
This is my code:
import UIKit
class ExampleViewController: UIViewController {
#IBOutlet weak var myLabel: UILabel!
#IBOutlet weak var mySlider: UISlider!
override func viewDidLoad() {
super.viewDidLoad()
myLabel.font = UIFont.monospacedDigitSystemFont(ofSize: 15, weight: .bold)
}
#IBAction func sliderChanged(_ sender: UISlider) {
myLabel.text = String(format: "%.5f is the actual Value of the Slider", sender.value)
}
}
GIF about the jiggle:
Any suggestions? Am I missing something?
This is a horrible bug and it's caused by the monospaced font being bold. Setting the weight to regular solves this problem.
myLabel.font = UIFont.monospacedDigitSystemFont(ofSize: 15, weight: .regular)
If you still want to use a bold font, consider using a non-standard monospaced font.

how to print uiview in label (swift3)

I am trying to print a uiview in a label. I don't know if I should put accessibilityIdentifier or not. When I did put accessiblitiyIdentifier in my whole app loaded but was all black.
#IBOutlet var pink: UIView!
#IBOutlet var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
label.text = pink
}
AccessibilityIdentifier can use for UI Automation scripts,
label.text = pink wont be compile
you can use label.addSubview(pink)
label.text is of type String and pink is of type UIView!, that shouldn't even compile?

Incorrect capitalization in UILabel

The code I am using:
#IBOutlet weak var tlabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
tlabel.font = UIFont(name: "Anxiety", size: 40)
tlabel.numberOfLines = 0
tlabel.text = "Test"
}
The text "Test" gets capitalized ("TEST" appears on the screen). How can I avoid this?
A quick google seems to show that the font Anxiety does not have any non capital letters in the font. So if you want to use non capital letters you have to find another font.
http://www.1001freefonts.com/anxiety.font

How to change text UILabel in swift code?

I'm new to swift and I am trying to understand UILabel text property
Based on what I have read, my understanding is that I can replace text with any String . So I did
The text property is "read-only" , is there a way I can change text label by hardcoding in swift ?
I am not in front of my computer to verify this, but I don't think you need to mark it as "self"
Just Food.text = "Burger"
Additionally. It is common for you to put variables with the first letter as lower case with each other words first letter being upper case
For example.
var firstWord = "Traditionally the best way to code"
Capital first letter first word is traditionally used for classes.
Example
Class NewClass = "Blah Blah"
You cannot set a value like this in the declaration section of the class.
Since you're working with a UIViewController, you'll want to go to the viewDidLoad() method and put self.Food.text = "Burger" there.
For example:
import UIKit
class TestViewController: UIViewController {
#IBOutlet weak var Food: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.Food.text = "Burger"
}
}
The viewDidLoad() method is called by the system when (coincidentally enough) the view is first loaded. After the view has loaded, you are free to make any edits to any of the objects on the screen. viewDidLoad will be where you will want to perform the majority of the setting up of your view.
100% programatically would be like this. This both creates the label and the string.
override func viewDidLoad()
{
super.viewDidLoad()
var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
label.center = CGPointMake(160, 284)
label.textAlignment = NSTextAlignment.Center
label.text = "Burger"
self.view.addSubview(label)
}

Resources