How to add a fixed bar on the mapView on iOS

How to add a fixed bar on the mapView on iOS



Recently, I have made a simple project which needs to use GoogleMap Api.



I think that my Question is so simple and easy,
but i don't know how to complete it.



Well this is my problem



please check the following image.(This is what i want to make.)



enter image description here



How can i put the bars on the view and let the bars can be seen in the simulator? plz let me know



(i dont upload code cuz it's not the problem about the code, just want to know about the concept of how to insert view(or layer?) like that)




1 Answer
1



First, let say you have a map view:


let camera = GMSCameraPosition.camera(withLatitude: 11.5449, longitude: 104.8922, zoom: 12)
let map = GMSMapView.map(withFrame: .zero, camera: camera)
map.isMyLocationEnabled = true
self.view = map



Then, you can just add your top and bottom views to the view as normal


let topBar = UIView()
view.addSubview(topBar)
let bottomBar = UIView()
view.addSubview(bottomBar)



And if you want to add other views such as texts and buttons, you can add them as subviews to the topBar or bottomBar view


let button = UIButton()
topBar.addSubview(button)



Noted: to put the views in the exact locations as in the image, you need to specify their locations.
For example:


bottomBar.frame = CGRect(x: 0, y: view.bounds.height - 200, width: view.bounds.width, height: 200)



In storyboard:
I didn't use google maps so here I'm using the default MKMapView as an example.



First, let's say we have a map view covering the entire view controller:



enter image description here



Then for the top bar, let's add a view and give it some constraints:



enter image description here



Now for the back button and the title:



enter image description here



enter image description here



enter image description here



Now, for the bottom bar: first we need a view to hold all the things:



enter image description here



For the texts, we use 4 uilabels, embed them into a stack to make them lined-up. Give some spacing as well to make them look good:



enter image description here



Finally, for the image on the right, we can use uiimageview or uibutton:



enter image description here



Don't forget to add constraints to the stackview and the uiimageview/uibutton






Tthank you for your replying :) But.. Is there any way to make this view by storyboard? not the code.(except for googlemap)

– cslee92
Sep 10 '18 at 8:45






check my edited answer

– ssmeter
Sep 11 '18 at 2:41



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế