Polls on iOS
UIKit
import ViafouraSDK
let poll = VFPollViewController.new(
containerId: "YOUR_CONTAINER_ID",
loginDelegate: self,
settings: VFSettings(colors: VFColors(colorPrimary: .systemBlue)),
sectionUUID: nil, // optional; defaults to your site's section
syndicationKey: nil
)
poll.setTheme(theme: .light)
poll.setLayoutDelegate(layoutDelegate: self)
poll.setCustomUIDelegate(customUIDelegate: self)
addChild(poll)
view.addSubview(poll.view)
poll.didMove(toParent: self)To open a poll you already hold the content container UUID for, use the other overload:
let poll = VFPollViewController.new(
contentContainerUUID: contentContainerUUID,
loginDelegate: self,
settings: settings
)Actions
poll.setActionCallbacks { action in
switch action {
case .authPressed(let promptType):
// Reader tried to vote while logged out — present your login flow
break
default:
break
}
}VFLoginDelegate.startLogin() is called at the same moment, so you can present your login flow from either place. Once the reader is authenticated the pending vote is cast automatically.
Height
The widget reports its own height through VFLayoutDelegate, in points:
func containerHeightUpdated(viewController: VFUIViewController, height: CGFloat) {
pollHeightConstraint.constant = height
}The height is 0 whenever the widget hides itself, so a constraint driven by this callback collapses the widget without leaving a gap. It changes again whenever a moderator moves between the prompt, the editor and the poll, and when results replace the options.
SwiftUI
import ViafouraSDK
VFPollView(
containerId: "YOUR_CONTAINER_ID",
settings: settings,
sectionUUID: nil,
onLogin: { presentLogin() },
onAction: { action in
if case .authPressed = action {
presentLogin()
}
},
onHeightChange: { height in
// Optional — the view already sizes itself when autoSize is true
}
)VFPollView(contentContainerUUID:settings:...) opens a poll from its content container UUID instead. The view sizes itself by default (autoSize: true) and follows the environment colour scheme unless you pass an explicit theme:.
Styling
Colours, fonts and theme come from the VFSettings you pass in, and setTheme(theme:) switches the theme at runtime.
For finer control, VFCustomUIDelegate hands you these views:
VFCustomizableView case | View |
|---|---|
pollBackgroundView | The widget's root view |
pollHeaderLabel | The small header above the question (active with time remaining, or closed) |
pollQuestionLabel | The poll question |
pollMenuButton | The moderator menu button in the header |
pollOptionContainerView | One option row |
pollOptionLabel | An option's text |
pollOptionPercentageLabel | An option's percentage, once results are visible |
pollOptionRadioImage | The radio indicator shown before voting |
pollOptionVotedImage | The check mark on the option the reader chose |
pollOptionFillView | The results bar behind an option |
pollPrimaryButton | The primary button: create, submit, confirm |
pollSecondaryButton | The secondary button: cancel |
pollMessageTitleLabel | The title of the create prompt, login prompt and confirmations |
pollMessageTextLabel | The body text of those messages |
func customizeView(theme: VFTheme, view: VFCustomizableView) {
if case .pollPrimaryButton(let button) = view {
button.layer.cornerRadius = 20
}
}pollHeaderImage, pollDeleteLabel, pollDeleteImage, pollCloseLabel and pollCloseImage still exist for source compatibility but are deprecated and never handed to the delegate: moderator actions now live in pollMenuButton.
Updated 4 days ago
