Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8254047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:04:40+00:00 2026-06-08T01:04:40+00:00

Here I create two views(bar and icon) and I would like to make one

  • 0

Here I create two views(bar and icon) and I would like to make one call to @window.addSubview to add them both.

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @window = UIWindow.alloc.initWithFrame UIScreen.mainScreen.bounds
    @window.makeKeyAndVisible

    bar = UIView.alloc.initWithFrame [[0, 0], [320, 100]]

    icon= UIImageView.alloc.initWithFrame([[100,0], [100,100]])

    @window.addSubview bar   # I have two calls to addSubview
    @window.addSubview icon

  true
  end
end

I would like something like this:

@window.addSubview bar, icon

or

@window.addSubview [bar,icon]

I realize the difference is nominal but it seems like there should be a way to call addSubview on several views at once.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:04:41+00:00Added an answer on June 8, 2026 at 1:04 am

    I would say you are just begging to trip yourself and others up at a latter date by doing this, but if you must you can just reopen UIView and define the method yourself

    class UIView
      def addSubviews *views
        views.flatten.each { |view| addSubview view }
      end
    end
    

    This should allow

    @window.addSubviews [view_a, view_b]
    
    # OR
    
    @window.addSubviews view_a, view_b
    

    To try it out here is a full example

    class AppDelegate
      def application(application, didFinishLaunchingWithOptions:launchOptions)
    
        @window = UIWindow.alloc.initWithFrame UIScreen.mainScreen.bounds
        @window.makeKeyAndVisible
    
        view_a = UIView.alloc.initWithFrame [[100, 100], [100, 100]]
        view_a.backgroundColor = UIColor.greenColor
    
        view_b = UIView.alloc.initWithFrame [[200, 200], [100, 100]]
        view_b.backgroundColor = UIColor.redColor
    
        @window.addSubviews [view_a, view_b]
    
        true
      end
    end
    
    class UIView
      def addSubviews *views
        views.flatten.each { |view| addSubview view }
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a UIView has multiple UITextFields validates each one as
I am trying to make an app with two different tab bar controllers, one
I have two tables: entitytype and project . Here are the create table statements:
Alright so here are my two tables. CREATE TABLE [cards] ( [id] TEXT PRIMARY
Here is the code, I defined two class named Father and Son, and create
First.. here are the two tables I've created (sans irrelevant columns).. CREATE TABLE users_history1
I would like to present multiple modal views in sequence (e.g. show confirmation page
I have two views in my app, one is a general view where CoreLocation
I create a tab bar controller in the app delegate. Here is the .h
I'm trying to create an animation to transition between two views, both of which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.