LoginSignup
5

More than 5 years have passed since last update.

PageMenuのタブ幅をメニュータイトル長に追従させる【Swift3.0】

Last updated at Posted at 2016-11-28

PageMenuのタブ幅をメニュータイトル長に追従させる方法

.menuItemWidthBasedOnTitleTextWidth(true)をオプション配列に加える

// swift 3.0

// PageMenuの設定 (swift2.xバージョンではENUMパラメタ名の先頭が大文字です)
let parameters: [CAPSPageMenuOption] = [
    .menuHeight(45.0),
    .menuItemWidth(110.0),
    .centerMenuItems(true),
    .menuItemWidthBasedOnTitleTextWidth(true), // これをオプションに加える
    .menuMargin(6)
]

他にもいろいろなオプションが用意されています。

オプション列挙子一覧


public enum CAPSPageMenuOption {
    case selectionIndicatorBottomOffset(CGFloat)
    case selectionIndicatorHeight(CGFloat)
    case menuItemSeparatorWidth(CGFloat)
    case scrollMenuBackgroundColor(UIColor)
    case viewBackgroundColor(UIColor)
    case bottomMenuHairlineColor(UIColor)
    case selectionIndicatorColor(UIColor)
    case menuItemSeparatorColor(UIColor)
    case menuMargin(CGFloat)
    case menuItemMargin(CGFloat)
    case menuHeight(CGFloat)
    case selectedMenuItemLabelColor(UIColor)
    case unselectedMenuItemLabelColor(UIColor)
    case useMenuLikeSegmentedControl(Bool)
    case menuItemSeparatorRoundEdges(Bool)
    case menuItemFont(UIFont)
    case menuItemSeparatorPercentageHeight(CGFloat)
    case menuItemWidth(CGFloat)
    case enableHorizontalBounce(Bool)
    case addBottomMenuHairline(Bool)
    case menuItemWidthBasedOnTitleTextWidth(Bool)
    case titleTextSizeBasedOnMenuItemWidth(Bool)
    case scrollAnimationDurationOnMenuItemTap(Int)
    case centerMenuItems(Bool)
    case hideTopMenuBar(Bool)
    case menuShadowRadius(CGFloat)
    case menuShadowOpacity(Float)
    case menuShadowColor(UIColor)
    case menuShadowOffset(CGFloat)
    case addBottomMenuShadow(Bool)
    case iconIndicator(Bool)
    case iconIndicatorView(UIView)
    case showStepperView(Bool)
}

PageMenuのswift3.0バージョンはこちらから入手可能です。
https://github.com/orazz/PageMenu

インストールは、classesの下にある、CAPSPageMenu.swift をプロジェクトに追加するだけ。素敵ですね:grinning:

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5