subview

Swift: Get all subviews of a specific type and add to an array

六月ゝ 毕业季﹏ 提交于 2019-11-28 19:43:41
问题 I have a custom class of buttons in a UIView that I'd like to add to an array so that they're easily accessible. Is there a way to get all subviews of a specific class and add it to an array in Swift? 回答1: The filter function using the is operator can filter items of a specific class. let myViews = view.subviews.filter{$0 is MyButtonClass} MyButtonClass is the custom class to be filtered for. 回答2: Here you go extension UIView { /** This is the function to get subViews of a view of a

How can I insert a subview below the other subviews

这一生的挚爱 提交于 2019-11-28 19:43:15
问题 everyone. I have some labels that I draw them in the xib file, and add a background view using codes,but the background view is in the front of these labels, so I cant see them. So, my question is how can I add a background view below these labels. Thank you in advance. 回答1: If you Google UIView you'll end up at the documentation - UIView Class Reference Then you need to look down the list of methods until you find something that sounds like it will roughly fit your needs like these two: -

Scale UIView and all its children

孤者浪人 提交于 2019-11-28 18:07:35
I have an UIView with around 50 UIButtons. All button positions were given in pixels, relative to the left upper corner of my main UIView. All (background) images used in the view are available in higher resolution. As I am porting my app from iPhone to iPad, I would like to increase the effective pixel size of the UIView. Now I'm searching a way to upscale the whole UIView by a factor of 2*. Is that possible without destroying the position of the inner elements? FYI, the UIView is designed in a NIB-file in XCode. But I don't mind if it can be done programmatically. I ended up using self.view

Display navigationController on top

心不动则不痛 提交于 2019-11-28 14:26:59
I have set up a subview "popup" in my application and I want to show a navController if the user taps a button on the subview popup. I've set up the button so far, but if I tap the button the navigationController appears under my popup!? I've searched for some solution but I didn't found any. The whole controller is actually displayed in a folder which you can find here: https://github.com/jwilling/JWFolders So the viewDidLoad belong to the folder and the rootview. I tried to make it as a subview of the popup but that doesn't work too. Does anyone know how to treat that? I've set up the popup

iOS: ScrollView infinite paging - Duplicate end caps

你离开我真会死。 提交于 2019-11-28 11:33:01
I have a question about infinite paging in a ScrollView. In my app I have only 3 subviews in ScrollView. Each subview is loaded from xib file. Normally it looks like ABC in ScrollView. I wanted to make infinite paging so I added end caps and now it looks like CABCA. If the user is on the first C, it jumps to regular C and if user is on the last A, it jumps to regular A. Here is a code: - (void)scrollViewDidEndDecelerating:(UIScrollView *)sender { if (scrollView.contentOffset.x == 0) { [scrollView scrollRectToVisible:CGRectMake ((scrollView.frame.size.width * 3), 0, scrollView.frame.size.width,

How to create an alert in a subview class in Swift?

我的未来我决定 提交于 2019-11-28 06:19:00
问题 I have a view controller which contains a sub-view. And inside the sub-view class, I may need to pop out an alert when some condition is satisfied. class GameViewController: UIViewController { @IBOutlet var gameBoardUIView: GameBoardUIView ... } class GameBoardUIView: UIView { ... func move() { if !gameBoard.checkNextMoveExist() { var alert = UIAlertController(title: "Game Over", message: nil, preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Take Me Back",

Bringing a subview to be in front of all other views

谁都会走 提交于 2019-11-28 03:32:33
I am working on integrating an ad provider into my app currently. I wish to place a fading message in front of the ad when the ad displays but have been completely unsuccessful. I made a function which adds a subview to my current view and tries to bring it to the front using [self.view bringSubviewToFront:mySubview] The function fires on notification that the ad loaded (the notification is from the adprovider's SDK). However, my subview does not end up in front of the ad. I imagine this is made purposely difficult by the ad provider, but I wish to do it regardless. I am currently discussing

UISegmentedControl Best Practice

牧云@^-^@ 提交于 2019-11-27 17:27:57
I'm trying to work out the "best" way to use a UISegmentedControl for an iPhone application. I've read a few posts here on stackoverflow and seen a few people's ideas, but I can't quite sort out the best way to do this. The posts I'm referring to are: Changing Views from UISegmentedControl and How do I use a UISegmentedControl to switch views? It would seem that the options are: Add each of the views in IB and lay them out on top of each other then show/hide them Create each of the subviews separately in IB, then create a container in the main view to populate with the subview that you need

UITextView change height instead of scroll

时间秒杀一切 提交于 2019-11-27 14:10:49
问题 By default, the UITextView's contentView becomes scrollable when there is too much text to fit into the textview based on it's height. I'd like to disable this and instead, update the height of the UITextView to fit in the text. The reason I'm doing this is because I'm adding the UITextView as a subview of a UIScrollView which should handle the scrolling, much like in the native Mail app (when you enter text, the whole view scrolls up, not just the textview. Anyone got some ideas / has run

Difference between addSubview and insertSubview in UIView class

强颜欢笑 提交于 2019-11-27 11:16:32
What is the difference between addSubview and insertSubView methods when a view is added programmatically? mahboudz The only difference is in where the view is added: whether it is the frontmost view ( addSubview: ), or it is before the 5th subview, ( insertSubview:atIndex: ) or if it is immediately behind another subview ( insertSubview:aboveSubview: ). Using insertSubView: you can specify the index, which determines z-order of views. A view with a higher index lies above those with lower indices. I don't think there is a difference. addSubview: is simple a convenient method for [view