目標:

  • 點擊工作,可以看到工作內容

步驟:

Step 1

app/screens/homr_screen.rb 加入

  1. def view_job(args)
  2. open JobScreen.new(args)
  3. end

Step 2

  • potion g screen job

Step 3

修改 app/screens/job_screen.rb

加入

  1. class JobScreen < PM::Screen
  2. stylesheet JobScreenStylesheet
  3. attr_accessor :job
  4. def on_load
  5. self.title = @job.title
  6. @content = append!(UILabel, :job_content)
  7. @content.text = @job.content
  8. @image = append!(UIImageView, :job_image).style { |st| st.remote_image = @job.image_url }
  9. end
  10. def will_animate_rotate(_orientation, _duration)
  11. reapply_styles
  12. end
  13. end

修改 app/stylesheets/job_screen_stylesheet.rb

加入

  1. class JobScreenStylesheet < ApplicationStylesheet
  2. # Add your view stylesheets here. You can then override styles if needed,
  3. # example: include FooStylesheet
  4. def setup
  5. # Add stylesheet specific setup stuff here.
  6. # Add application specific setup stuff in application_stylesheet.rb
  7. end
  8. def job_content(st)
  9. st.frame = { top: 100, left: 20, width: 100, height: 30 }
  10. st.color = color.black
  11. end
  12. def job_image(st)
  13. st.frame = { top: 200, left: 10, width: 200, height: 200 }
  14. st.background_color = color.black
  15. end
  16. def root_view(st)
  17. st.background_color = color.white
  18. end
  19. end

修改 app/models/job.rb 加入 image_url 一個欄位

  1. class Job
  2. attr_accessor :id, :title, :content, :image_url
  3. def initialize(data)
  4. @id = data['id']
  5. @title = data['title']
  6. @content = data['content']
  7. @image_url = data['image_url']
  8. end
  9. # ....
  10. end

Step 4 :

  • rake

最後會生成

iOS guide 02 - 图1