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
Related
I'm just trying to simply set the background image of the button, but whatever I try it is doing nothing. I also put a UIImageView there to see if there's any issue with the image file, but the image view is set perfectly fine. Do I have to set something in the properties of the button?
Here the code:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let imageToSet = UIImage(named: "3-1")
b1.setBackgroundImage(imageToSet, for: .normal)
imageView.image = imageToSet
}
#IBOutlet weak var b1: UIButton!
#IBOutlet weak var imageView: UIImageView!
}
These are my setting for the button:
In Xcode 13 ,UIButton has four type are Plain,Grain,Tinted,Filled .When you create a button in storyboard , button type automatically set with Plain that means new UIButton configurations is on (If you set one of them 4).So when you try to use old behaviours like
setBackgroundImage(..)
setImage(..)
This functions not gonna effect on this button. So If you want to use old behaviours you need to set style Plain to Default
I added a label to my storyboard and did a CTRL drag to my ViewController.swift file, set as an Outlet and gave it a name but it's not clear to me how to print a variable such as the following to my label.
var userName = "Ted"
In Swift playgrounds I can run the following and it prints the variable just fine but I can't make it do that in the label/IBOutlet once I compile the app.
var userName = "Ted"
print(userName)
Here's my ViewController so far:
import UIKit
class ViewController: UIViewController {
var userName = "Ted"
#IBOutlet var userNameLabel: UILabel? = nil
override func viewDidLoad() {
super.viewDidLoad()
print(userName)
}
}
I'm using Xcode 9.3.1 and Swift 4.
Since your label is an outlet and it is connected through your storyboard, change:
#IBOutlet var userNameLabel: UILabel? = nil
to:
#IBOutlet var userNameLabel: UILabel!
Then in viewDidLoad, instead of print, set the label's text:
userNameLabel.text = userName
Every label have one property called text which is used to set/get value to/from label for example::
lblObj.text = "text you want to display"
print(lblObj.text) // output:: "text you want to display"
text property will only except string type, since your username is of type string you can assign it like below
userNameLabel.text = userName
I'm currently having problems for my label to read the addition of 3 textfield values automatically, without a button function action. As such i only want my textfield to be an Int input only. There's a screenshot attached below for better reference. Appreciate those who can help me with this. Thanks!
ViewController
import UIKit
class TryingoutController: UIViewController {
#IBOutlet var impact: UITextField!
#IBOutlet var rigour: UITextField!
#IBOutlet var response: UITextField!
#IBOutlet var total: UILabel!
One way is to add self as the target to the text fields, for the control event .editingChanged
impact.addTarget(self, action: #selector(textChanged), for: .editingChanged)
// do the same for other textfields
Then declare a textChanged method. This should handle what happens when the texts in the text fields change. One implementation would be to add up all the values in the text fields (if any, and is valid) and display it in the label.
func textChanged() {
let impactValue = Int(impact.text!)
let rigourValue = Int(rigour.text!)
let responseValue = Int(response.text!)
total.text = String(describing:
(impactValue ?? 0) + (rigourValue ?? 0) + (responseValue ?? 0)
)
}
Optionally, you can conform to UITextFieldDelegate:
class TryingoutController: UIViewController, UITextFieldDelegate {
}
and implement shouldChange according to this answer by Thuggish Nuggets. Then, set the delegates of the text fields to self:
impact.delegate = self
// do the same for other text fields.
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
Hi I am trying to make a FB Like button in my app. I have seen a lot of posts and they are old and not clear for me.
Here is what I did:
import FBSDKCoreKit
import FBSDKShareKit
class MyClass{
#IBOutlet weak var fbLikeButton: FBSDKLikeButton!
override func viewDidLoad() {
super.viewDidLoad()
self.fbLikeButton.objectID = "MyPage"
}
}
In the story board I Chose FBSDKLikeButton as class for the button in the Identity inspector.
Now:
1. This dosent work.
2. I want to do the FBSDKLikeControlStyle.BoxCount if possible.
I tried to do like this without FBSDKLikeButton as class for the button in the Identity inspector :
import FBSDKCoreKit
import FBSDKShareKit
class MyClass{
#IBOutlet weak var contentView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let likeControl:FBSDKLikeControl = FBSDKLikeControl()
likeControl.objectID = "MyPage"
likeControl.likeControlStyle = FBSDKLikeControlStyle.BoxCount
likeControl.frame = CGRectMake(15, 15, 200, 40)
likeControl.likeControlHorizontalAlignment = .Left
self.contentView.addSubview(likeControl)
}
}
It appeared but it didnt affect number of likes.
Any clear direct solution?! All the posts are old. I hope this will be a new clear one.
Thx