Using FB Like Button in Native iOS Swift App - ios

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

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

How to use MPVolumeView in order to change Audio output device. Like WhatsApp and hangout

I am trying to achieve the functionality that allows to switch between different audio outputs i.e. Bluetooth, earphone or default iPhone.
same like whatapps and and hangouts are doing can anyone suggest me how i should go for it.
Yeah finally achieved expected output. preety simple.
import UIKit
import MediaPlayer
class ViewController: UIViewController {
#IBOutlet weak var mpvolumeParentView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let mpVolumeView = MPVolumeView(frame: mpvolumeParentView.bounds)
mpVolumeView.showsRouteButton = true
mpVolumeView.showsVolumeSlider = false
mpVolumeView.setRouteButtonImage(UIImage(named: "IMAGE_NAME"), for: .normal)
mpvolumeParentView.addSubview(mpVolumeView)
}
}

Using LOTAnimationView with Auto Layout in Storyboard

Is there a way to use LOTAnimationView (Lottie framework) with auto layout? I tried setting the class of a UIView to LOTAnimationView in my storyboard, but getting nil IB outlet..
Should be set like this in latest Lottie version:
and set animation name here:
and here is example code:
import UIKit
import Lottie
class ViewController: UIViewController {
#IBOutlet weak var animationView: AnimationView!
override func viewDidLoad() {
super.viewDidLoad()
animationView.play()
}
}
Take an outlet of LOTAnimatedControl.
Assign your JSON file to LOTAnimationView
lot.animationView.setAnimation(named: "checked_done_")
Complete example:
import UIKit
import Lottie
class ViewController: UIViewController {
#IBOutlet weak var lot: LOTAnimatedControl!
override func viewDidLoad() {
super.viewDidLoad()
lot.animationView.setAnimation(named: "youranimationjsonfile")
lot.animationView.play()
}
}
Hope this will help you.
Update for the latest Lottie version with Ashish Kakkad's comment.
Change class name AnimationView instead of LOTAnimatedControl,
and then set property animationName from Interface Builder

Changing an image using swift for iOS App

So I am trying to load a picture programmatically using Swift and I am having some trouble. I can change the UIImage of a view using the Attributes Inspector, so I know the picture I am using is added properly and I am using the right name.
Here is the code I am using:
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var myPicture: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
myPicture.image = UIImage(named:"myNewPic")
}
}
I think there might be some setting I am missing in Attributes inspector or something since the code is pretty simple and I know the image is added properly.
Any help would be appreciated.
Make sure that your image name is correct. You have image properly in xcode and your outlet is properly connected
add image with extension if you are not using assets for images. like myNewPic.png or myNewPic.jpg whatever extension it is.
So, your code should be like,
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var myPicture: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
myPicture.image = UIImage(named:"myNewPic.png") //or .jpg or else
}
}
another choice
if you load image from assets usemyNewPic if you load from bundle use myNewPic.png (with extensions).
if let img = UIImage(named: "myNewPic") {
myPicture.image = img
} else {
myPicture.image = UIImage(named:"myNewPic.Imageextensions")
}

Issue when adding a Facebook like button to my iOS app

I'm experimenting adding a Facebook like button to my app using swift. This is my code and also the steps I exactly took until now. I am wondering if I am missing doing any steps or if there is something wrong with the code?
1- Created a new Xcode project using Swift
2-added the following code to viewDiDLoad
3-imported "import Parse" and "import Social" as seen below
4-Created a bridging header file and imported FBSDKCoreKit/FBSDKCoreKit.h and FBSDKShareKit/FBSDKShareKit.h into it.
5-Added FBSDKCoreKit and FBSDKShareKit to my frameworks
And then I'm getting an "expected declaration" error on this line:
likeButton.objectID = "https://www.facebook.com/JCVDonline/?fref=ts"
Here is the full code:
import UIKit
import Parse
import Social
class NewsPageViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var likeButton:FBSDKLikeControl = FBSDKLikeControl()
likeButton.objectID = "https://www.facebook.com/JCVDonline/?fref=ts"
likeButton.likeControlStyle = FBSDKLikeControlStyle.BoxCount
likeButton.frame = CGRectMake(16,20, 290, 40)
self.view.addSubview(likeButton)
}
}
The issue was I wanted to push a button and then have the like button show up. So I added an IBAction and it's working like gold! next for me is to figure a way to change the button image :)
here is the working code by the way:
import UIKit
import Parse
import Social
class NewsPageViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func likeOnFacebook(sender: AnyObject) {
var likeButton:FBSDKLikeControl = FBSDKLikeControl()
likeButton.objectID = "https://www.facebook.com/JCVDonline/?fref=ts"
likeButton.likeControlStyle = FBSDKLikeControlStyle.BoxCount
likeButton.frame = CGRectMake(16,20, 290, 40)
self.view.addSubview(likeButton)
}
}

Resources