Giter Club home page Giter Club logo

Comments (10)

markrickert avatar markrickert commented on August 17, 2024

I think this should work:

@button = add UIButton.buttonWithType(UIButtonTypeRoundedRect), {
  # Other stuff here
}

# You have to set the title of a uicontrol with a method call instead of 
# an attribute because of the different states a uicontrol can be in.
@button.setTitle("My Title", forState: UIControlStateNormal)

good luck!

from promotion.

klancaster avatar klancaster commented on August 17, 2024

Sorry if this is a stupid question, but going along with this, can you
set the action for the button in the hash?

On Sun, May 26, 2013, at 09:52 AM, Mark Rickert wrote:

I think this should work:

@button = add UIButton.buttonWithType(UIButtonTypeRoundedRect), {

Other stuff here

}

You have to set the title of a uicontrol with a method call instead of

an attribute because of the different states a uicontrol can be in.

@button.setTitle("My Title", forState: UIControlStateNormal)

good luck!

Reply to this email directly or [1]view it on GitHub.
[b3SzVy4EPn2GCWwhLcu-3CVqELCcNRSCKMj6MTCCccXEFjEr7QrQPFvY6mVx6BC9.gif]

References

  1. #95 (comment)

from promotion.

markrickert avatar markrickert commented on August 17, 2024

I don't believe so. You would probably be best creating the element and putting it on the screen and then using something like bubblewrap's on_tapped event handler with a block or function callback - https://github.com/rubymotion/BubbleWrap#ui

from promotion.

jamonholmgren avatar jamonholmgren commented on August 17, 2024

Actually, @markrickert, there's an undocumented feature of set_attributes that allows for doing that syntax:

@button = add UIButton.buttonWithType(UIButtonTypeRoundedRect), {
  "setTitle:forState:" => [ "My Title", UIControlStateNormal ],
  "addTarget:action:" => [ self, :my_custom_action ]
}

I want to DSL the addTarget:action: one into just action:. Shouldn't be too difficult.

from promotion.

beauohara avatar beauohara commented on August 17, 2024

@markrickert Your suggestion works for me. Thanks!

The following produced a fully working button with action that responds to button touch:

@button2 = add UIButton.buttonWithType(UIButtonTypeRoundedRect), {
      frame: CGRectMake(20, 80, 280, 40),
      "setTitle:forState:" => [ "Customers", UIControlStateNormal ],
      "addTarget:action:forControlEvents" => [ self, :view_customers, UIControlEventTouchUpInside ]
    }

from promotion.

markrickert avatar markrickert commented on August 17, 2024

👍

from promotion.

jamonholmgren avatar jamonholmgren commented on August 17, 2024

Awesome, @beauohara .

from promotion.

ricsrock avatar ricsrock commented on August 17, 2024

How could I add a "parameter" to the method that this button calls?

So, if my action is :archive_customer and I need to send back the customer_id when this button is tapped, how would I do that?

from promotion.

markrickert avatar markrickert commented on August 17, 2024

I'd advise making things a bit easier with BubbleWrap

Like so:

@button2 = add UIButton.buttonWithType(UIButtonTypeRoundedRect), {
  frame: CGRectMake(20, 80, 280, 40),
  "setTitle:forState:" => [ "Customers", UIControlStateNormal ]
}

@button2.when(UIControlEventTouchUpInside) do
  archive_customer("some_customer_id")
end

from promotion.

ricsrock avatar ricsrock commented on August 17, 2024

Thanks!

from promotion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.