colinta / teacup

This project has been sunset in favor of MotionKit
github.com/motion-kit/motion-kit
Other
602 stars 85 forks source link

[HELP] failed on set font/titleColor for UIButton #110

Open anguskwan opened 11 years ago

anguskwan commented 11 years ago
  style :clickme,
        origin: [10, 10], extends: :rounded_button,
        title: "Click Me!"

  style :rounded_button,
        width: 300,
        height: 50,
        #font: "Helvetica".uifont(20),
        #titleColor: "#FFFFFF".uicolor,
        backgroundColor: UIColor.tealColor,
        layer: {
            #shadowColor: "#c6c6c6".uicolor,
            shadowOpacity: 0.5,
            shadowOffset: CGSizeMake(2.0, 4.0),
            shadowRadius: 3.0,
            masksToBounds: false,
            cornerRadius: 8
        },
        clipsToBounds: true

image

  1. if i set font on, the shadow will disappear ... why?
  2. how to set titleColor、shadowPath accurately?something like the code in https://github.com/bennyguitar/Colours-for-iOS/blob/master/ColoursDemo/ColoursDemo/ViewController.m

thank you :)

colinta commented 11 years ago

I'll try to duplicate this, could you create a small project that includes this code? It would help me fix it faster if I could clone a project and get it working (plus that way I know that the code reproduces the bug)

anguskwan commented 11 years ago

i am using ProMotion with TeaCup, the main code is:

  1. app_delegate.rb

class AppDelegate < PM::Delegate

  def on_load(app, options)
    open ArticleScreen.new(nav_bar: true)
    #open Colours.new
  end
end
  1. colours_screen.rb
class Colours < PM::Screen

  stylesheet :about

  layout :root do
    @scroll = subview(UIScrollView, :content) do
      @btn1 = subview(UIButton.custom, :clickme)
      subview(UILabel, :title)
      subview(UILabel, :about)
      subview(UIView, :line)
    end
  end

  def on_load

  end

end
  1. colours_style.rb
# -*- encoding : utf-8 -*-
Teacup::Stylesheet.new(:about) do
  style :root,
        backgroundColor: UIColor.whiteColor

  style :content,
        constraints: [:top, :full],
        backgroundColor: UIColor.whiteColor

  style :clickme,
        origin: [10, 10], extends: :rounded_button,
        title: "Click Me!"

  style :title,
        constraints: [:full_width, constrain_below(:clickme, 10), :center_x, constrain_height(30)],
        font: 'Cassannet Regular'.uifont(20),
        textAlignment: UITextAlignmentCenter,
        numberOfLines: 1,
        text: '-------------------------------'

  style :about,
        constraints: [constrain_width(220), constrain_below(:title, 40), :center_x, constrain_height(200)],
        font: 'Arvo'.uifont(11),
        textAlignment: UITextAlignmentCenter,
        numberOfLines: 0,
        text: "trying teacup to styling app"

  style :line,
        constraints: [constrain_below(:about, 10), constrain_size(220, 1), :center_x],
        backgroundColor: '#c6c6c6'.uicolor

  style :rounded_button,
        width: 300,
        height: 50,
        #font: "Helvetica".uifont(20),
        #titleColor: "#FFFFFF".uicolor,
        backgroundColor: UIColor.tealColor,
        layer: {
            #shadowColor: "#c6c6c6".uicolor,
            shadowOpacity: 0.5,
            shadowOffset: CGSizeMake(2.0, 4.0),
            shadowRadius: 3.0,
            masksToBounds: false,
            cornerRadius: 8
        },
        clipsToBounds: true
end

can this help ?

colinta commented 10 years ago

Hi, I was not able to reproduce your project (a repo that I can clone would be best, I have very limited time to investigate these issues).

At the least, I think the shadowColor should be a CGColor. e.g. shadowColor: '#c6c6c6'.uicolor.cgcolor