CCKit2
    Preparing search index...

    Class CCSegmentedButton

    A segmented button displays multiple buttons in a single view, with only one selected at a time.
    Example image

    TypeScript
    let segmentedButton = new CCSegmentedButton({x: 1, y: 1, width: 25, height: 1}, ["Main", "Browse", "Options"], (_, id) => this.selectTab(id));
    this.view.addSubview(segmentedButton);
    Lua
    local segmentedButton = LuaWrappers.new(CCSegmentedButton, {x = 1, y = 1, width = 25, height = 1}, {"Main", "Browse", "Options"}, function(_, id) self:selectTab(id) end)
    self.view:addSubview(segmentedButton)

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new segmented button.

      Parameters

      • frame: CCRect

        The frame for the button. This should have a height of 1.

      • buttons: string[]

        The text for each button. This must have at least one button.

      • action: (this: void, sender: CCSegmentedButton, selection: number) => void

        The action to call when a selection changes

      Returns CCSegmentedButton

      If the button text list is empty

    Properties

    _isEnabled: boolean = true
    acceptsFirstResponder: boolean = true

    Whether the object can become the first responder.

    action: (this: void, sender: CCSegmentedButton, selection: number) => void

    The function to call when the selection changes.

    isFocused: boolean = false

    Whether the view is currently focused.

    isHidden: boolean = false

    Whether the view is hidden.

    needsDraw: boolean = true

    Whether the view needs to be redrawn.

    needsLayout: boolean = false

    Whether the view needs to be laid out.

    needsUpdateConstraints: boolean = false

    Whether constraints need to be updated.

    nextResponder?: CCResponder

    The next responder in the responder chain.

    subviews: CCView[] = []

    The list of subviews inside this view.

    superview?: CCView

    The view that contains this view, if it exists.

    userInteractionEnabled: boolean = true

    Whether user interaction is enabled for this view.

    window?: CCWindow

    The window this view is located inside.

    Accessors

    • get backgroundColor(): number | undefined

      The background color of the view.

      Returns number | undefined

    • set backgroundColor(value: number | undefined): void

      Parameters

      • value: number | undefined

      Returns void

    • get buttonCount(): number

      The number of buttons in the segmented button.

      Returns number

    • get buttonSelectedColor(): number

      The color of the button when in default state.

      Returns number

    • set buttonSelectedColor(value: number): void

      Parameters

      • value: number

      Returns void

    Methods

    • Adds a new button to the list of buttons.

      Parameters

      • text: string

        The text for the button

      • index: number = ...

        The index to place the number after (defaults to the end)

      Returns void

    • Adds a list of constraints to the view. The first item of the constraints MUST be this view.

      Parameters

      Returns void

      CCLayoutConstraint.active A safer way to enable a constraint

    • Notifies the object that it's about to become the first responder.

      Returns boolean

      Whether to accept the first responder status

    • This is used to place a blinking cursor on screen while not drawing. It's only called on the first responder of a window.

      Returns [CCPoint, number] | undefined

      The position and color of the cursor in window coordinates, or undefined to not place a cursor

    • Displays a view in the specified rectangle. This should not be called by other code.

      Parameters

      • rect: CCRect

        The rectangle to draw inside

      Returns void

    • Draws the view inside the specified rectangle. Override this function to provide custom view types.

      Parameters

      • rect: CCRect

        The rectangle to draw inside

      Returns void

    • Returns the text for a button by index.

      Parameters

      • index: number

        The index to get

      Returns string | undefined

      The text for the button, or undefined if out of range

    • Returns the furthest descendant that contains the specified point.

      Parameters

      • point: CCPoint

        The point to look for

      Returns CCView | undefined

      The deepest view that hit the point, or undefined if none was found

    • Sends a list of key input events to the input manager, which will send back text input events through insertText(text: string).

      Parameters

      • events: CCEvent[]

        The input events to send

      Returns void

    • Lays out the view hierarchy following constraints. This should only be called on a superview, which is done automatically.

      Returns void

    • Returns a context menu to display on a (usually right-click) event.

      Parameters

      • event: CCEvent

        The event that triggered the menu

      Returns CCMenu | undefined

      A context menu, or nil to not display a menu

    • Handles when a method action fails to find a responder.

      Parameters

      • method: string

        The method that was attempted

      Returns void

    • Removes a button from the list.

      Parameters

      • text: string

        The text for the button to remove

      Returns void

      If this would remove the last remaining button

    • Removes a button from the list.

      Parameters

      • index: number

        The index of the button to remove

      Returns void

      If the index is out of range, or this would remove the last remaining button

    • Notifies the object that it's about to no longer be the first responder.

      Returns boolean

      Whether to resign first responder status

    • Tells the receiver that the frame or constraints of the sender changed. This triggers the receiver to update its constraints if any are related to the sender, and cascades the message up and down throughout the hierarchy. It will also trigger a cascade on itself if it needs to update constraints.

      Parameters

      • sender: CCView

        The view whose frame and/or constraints changed

      • previous: CCView

        The view that called this method, to prevent backtracking

      Returns void

    • Attempts to call the specified method on the object, passing the call on to the next responder if this object doesn't implement it.

      Parameters

      • method: string

        The name of the method to call

      • ...args: any[]

        Any parameters to pass to the method

      Returns boolean

      Whether a responder was able to respond to the method

    • Adds a number of constraints to views using code. This can simplify settings constraints by using familiar code syntax instead of lengthy constraint constructions and activations.

      The syntax is fairly simple:

      <ViewName>.<Attribute> = [<Multiplier> *] <ViewName>.<Attribute> [+|- <Constant>]
      <ViewName>.<Attribute> = <Constant>
      

      The code is processed using Lua as the parser, so it's not strictly required to be in exactly this format; but mind that operators other than add/sub/mul/div/unm aren't supported (and division is only valid if the divisor is a number), and no libraries are available in the environment.

      Parameters

      • code: string

        The constraint code to apply

      • views: { [name: string]: CCView }

        A key-value map of names of views in the code, to the views they represent

      Returns void