customizing the share extension design in swift 2 - ios

I want to customize the design for share extension in swift 2. how can I do the customizations
class ShareViewController: SLComposeServiceViewController,NetworkSelectionViewControllerDelegate, PublishSelectionViewControllerDelegate{
var selectedNetworkName = "Default"
var selectedPublishName = "Select"
override func isContentValid() -> Bool {
// Do validation of contentText and/or NSExtensionContext attachments here
return true
}

You can create a custom Share Extension based on UIViewController:
Use the Xcode Share Template
The Xcode Share template provides default header and implementation
files for the principal view controller class (called
SharingViewController), an Info.plist file, and an interface file
(that is, a storyboard or xib file).
NOTE:
To provide a custom compose view instead of the standard one, deselect
“Use standard social compose interface” in the Xcode target-adding
pane. When this checkbox is deselected, the default
SharingViewController class is based on NSViewController or
UIViewController, depending on the platform you chose.

Related

How to show Storyboard UI using NSExtensionPrincipalClass for sharing extension

I am implementing share extension functionality in iOS app. I am able to use "NSExtensionPrincipalClass" in share extension's Info.plist file. And I have added custom MyViewController i.e.
import UIKit
#objc(MyViewController)
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("My view loaded!!!!")
// Do any additional setup after loading the view.
}
}
I have created storyboard with "MyViewController" and it's sample UI.
How do I show UI from storyboard created for "MyViewController".?
When I run the app it prints "My view loaded!!!!" but not able to bind to UI i.e. UI is blank. How do I set UI for MyViewController from storyboard?
You need to replace NSExtensionPrincipalClass with NSExtensionMainStoryboard:
NSExtensionMainStoryboard
String - iOS, macOS. Specifies the name of the app extension’s main storyboard file, minus the .storyboard filename extension. This key, if used, must be placed as an immediate child of the NSExtension key.

Inherit background color and other attributes for many UIViewControllers

For an iOS9+/Swift 3 app with many UIViewControllers, what is the best practice way of inheriting the same background colors and other common attributes (fonts, spacing, etc...). Is it best to have a common base class? Or some sort of protocol?
Because most visual attributes are associated with specific UIViews and UIView subclasses (like UILabel, UIButton, etc.), I would suggest that having this handled at the UIViewController level is forcing the view controller to be responsible for too many details specific to other classes.
Apple's built-in mechanism for setting global visual attributes on various views is the UIAppearance API. There's a good overview of that on NSHipster
The downside of using UIAppearance is that is doesn't easily accommodate variations in styling, like some buttons being red and some buttons being blue. It's basically a fixed default appearance for all instances of a certain view across the app.
I personally prefer using a dedicated styling framework that allows for applying combinations predefined styles to views. I have written about this and also created a framework to facilitate creating styles for UIKit components and applying and previewing them inside storyboards.
You could have a constants file with UI constants. Just refer to those variables in all view controllers and if you need to make changes everything else will change too.
You could also have an extension for certain things. I usually have an extension on UIColor that returns a color and I can change it in the extension and it will change everywhere else.
e.g.
extension UIColor{
class func selectedBlue() -> UIColor {
return UIColor(red:0.25, green:0.58, blue:0.97, alpha:1)
}
}
You can have a common base class for a desired component e.g for setting background color of your views, Create a subclass let its name be BackgroundView.
class UHBView: UIView {
override func awakeFromNib() {
super.awakeFromNib()
self.backgroundColor = UIColor.blueColor(); //Any color you want
}
}
Now set this subclass as a custom class in identity inspector in Interface Builder for any view.

Xcode 7.3 can't create xib with for UIView / UITableViewCell together

After I have updated to Xcode to 7.3, I found Xcode can't create Xib file, when I create UIView class or UITableViewCell. Does anybody know the reason?
Very traditional way and existing with any XCode version.
Right click on left panel
Select new file
Select iOS
Select User Interface
Select Empty then next
Give file name.
That will create empty xib, now drag and drop UITableViewCell and give class name as you have given in .h and .m file or swift file name.
Swift class with UITableViewCell
import UIKit
class CustomCell: UITableViewCell {
#IBOutlet weak var lblName : UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
Yeah, this is a surprising issue.
First create a nib (e.g. ProfileHeaderView.xib) file from File -> New file.
Then create a .swift (e.g. ProfileHeaderView.swift) file and subclass it from UIView.
Last (but not the least of course), go to Identity Inspector of your .xib file and change the name of class to the name of the created .swift file (e.g. ProfileHeaderView.swift).
Hope that helps.
Make sure that you select Cocoa Touch Class in iOS section, rather than OSX's Cocoa Class. That lets you check option Also create XIB File. This works perfectly in Xcode 7.3 for ViewControllers, and any UIView subclasses (e. g. UITableViewCell, UICollectionViewCell)
EDIT: but not for UIView

Xcode 6 interface builder does not show custom class

I have an error in my Xcode 6.3 interface builder.
When i create a new custom class and want to add it to interface builder custom class field. It is not available. I do use Swift as languag.
What I tried:
delete derived data
reinstall Xcode
cleand project
created new project
Class name is same as file name
Superclass and interface builder class are the same
Nothing worked out ;-( Any idea what it could be ?
I had the same issue and thought it as a bug. But it was my misunderstanding.
What actually happens is:
Custom Class drop down list shows only those custom classes which are subclasses of currently selected object's class.
For example, if we have imageview object in xib and after selecting it, when we see custom class drop down list, it'll show only custom classes inherited from (subclass of) UIImageView.
What I was doing wrong was looking for those custom classses which are subclasses of UIView.
In your case, it might be, not 100% sure, happening due to your TimerCVC is a subclass of UICollectionViewController instead of UIViewController.
TimerCVC is not a subclass of UIViewController
Press ctrl-n -> on the left panel choose iOS ->Source -> Cocoa Touch Class -> from the dropdown menu choose UIViewController -> And then fill the name field (automatically Xcode autocomplete with ViewController on the end).
It should look like this
import UIKit
class TimerViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

Swift #IBInspectable properties in a framework not displayed to Interface Builder

I'm trying to make a framework of a custom UIViewController using #IBInspectable to edit its properties in Interface Builder.
public class BWWalkthroughPageViewController: UIViewController {
#IBInspectable public var speed: CGPoint = CGPointZero
#IBInspectable public var speedVariance: CGPoint = CGPointZero
#IBInspectable public var animationType: String = ""
#IBInspectable public var animateAlpha: Bool = false
}
If the framework source code is in a sample app project, the properties come up to Attribute Inspector as shown in the image below,
but if I add the built framework to my app project, the properties are not displayed in the inspector.
Is it possible to show the inspectable properties in a built framework to Interface Builder? If possible, how to?
Here is the framework source code, which is forked from a non-framework project.
https://github.com/yoichitgy/BWWalkthrough/tree/support-carthage
Creating framework
Create default framework and add there your swift files.
Then set your swift files as public.
After that copy your framework and add it to your project folder
Use the framework
Add the framework in your project
Create new viewController in your storyboard and set viewController's class which is located in your framework
Thats all. You will see your your properties in the storyboard.
The reason the attributes won't show up in Interface Builder in your app but do in your framework is because your framework isn't a target of your app. The easiest way to ensure that it is included is to use Cocoapods, it'll handle everything nicely for you and the setup is relatively easy.
A side note: IBDesignable and IBInspectable really don't have anything to do with each other. With IBInspectable, you can expose a limited amount of property types to Interface Builder or a Storyboard (things like NSNumber, Bool, UIColor, etc). IBDesignable however is used to live render your views in a nib or storyboard. They're very handy to use together i.e. changing properties for your inspectable attributes and seeing your view rendered.

Resources