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 caseView
pollBackgroundViewThe widget's root view
pollHeaderLabelThe small header above the question (active with time remaining, or closed)
pollQuestionLabelThe poll question
pollMenuButtonThe moderator menu button in the header
pollOptionContainerViewOne option row
pollOptionLabelAn option's text
pollOptionPercentageLabelAn option's percentage, once results are visible
pollOptionRadioImageThe radio indicator shown before voting
pollOptionVotedImageThe check mark on the option the reader chose
pollOptionFillViewThe results bar behind an option
pollPrimaryButtonThe primary button: create, submit, confirm
pollSecondaryButtonThe secondary button: cancel
pollMessageTitleLabelThe title of the create prompt, login prompt and confirmations
pollMessageTextLabelThe 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.


Did this page help you?