I have a uiview subclass that i want to expand evenly. I mean I want the origin point of the view to be in the center, and have the width and height expand the same amount. Right now the origin point is in the top left, (0,0), and it expands down to the right. How would I go about doing this?
2
There are 2 best solutions below
0
Vaseltior
On
I suggest, if I understand you problem that you get the size of the superview in which the view is located. Let this view be view. Then, let your view be myView.
So all you have to do is the following :
Take half of the size of the screen for width and height values, and to position the origin of your view.
UIView view = myView.superview;
if (nil != view) {
// Make sure your view won't extend by itself with this
myView.autoresizingMask = UIViewAutoresizingNone;
// Get The size of the parent view
CGSize size = view.bounds.size;
// Set the new frame of your view
myView.frame = CGRectMake(size.width/2.0f,
size.height/2.0f,
size.width/2.0f,
size.width/2.0f);
}
And now your view is positioned correctly
Related Questions in IPHONE
- UIWebView Screen Fitting Issue
- ios responsive design not working (too wide in portrait orientation)
- Setting View orientation to portrait is ignored
- How do I add custom cells to TableView in Swift?
- UIWebView not loading URL in simulator
- What is the limit for number of subscribers to a stream(publisher's) in opentok/tokbox iOS SDK?
- How to generate request format for WCF web service method for Mac and iPhone
- Difference between gethostname() and [NSProcessInfo hostName]?
- How to force close ipad/iphone keypad when input element is not focused using JS?
- iOS app rejected because of in-app purchase
- iOS coordinates for iPad and iPhone game using spritekit
- What is the best practice when making a storyboard for iPhone and iPad?
- Labels properties changing in Xcode
- Terminating app due to uncaught exception
- Exchange plist data between 2 iPad using iCloud
Related Questions in UIVIEW
- Enable user interaction for gesture recognizer during UIView.animateWithDuration()
- Swift - Changing UIView programmatically while keeping IBOutlets (File's Owner)
- Changing UIView's xib file and file owners code on UISegmented controller switch
- Objective c keyboard opens unwillingly
- Create a UIView title of a push view using the index of an array
- iOS CGRect is inside another CGRect
- Drawing in UIView on touch points gives blurr drawing effect on boundaries
- How to vertically center two views & divide the width equally relative to the super view?
- On xib, dragging view will automatically go inside a bigger view
- Make a UIView stick to bottom of the ViewController frame in Swift
- How to convert a UIView to an image
- Draw/Paint like sketch color inside a bezier path in UIView
- Scene Kit: projectPoint calculated is displaced
- How to send a UIView element backwards in Swift
- UIView animation not smooth, jerky on repeat
Related Questions in RESIZE
- How to resize images with PHP PARSE SDK
- Problems with Clickable Divs in side bar
- Resizing images failing on start, setContentView & bitmap factory[android]
- HTML, CSS | Page Blurs on resize
- A view that can be moved and resized on android
- Creating a vertically draggable container in Adobe Flex 3.5
- Resize <iframe> so that whole content just scales down or up
- How to resize a flexible text-area on a mobile device?
- Why is my array of struct not resizing with Array.Resize?
- Resize image to the size of JLabel taken dynamically from file chooser in Swing app
- Best way to resize top banner images (viewport/html)
- Python Resize Multiple images ask user to continue
- Resize flexlslider at the end of window resize
- Resize a UITableView
- Error on running "adb shell wm density 240" for changing Android device density
Related Questions in FRAME
- How to open and read video stream in Matlab
- How to get the time stamp of each frame of a GoPro video in MATLAB?
- AS3 Get currentFrame of current MovieClip
- Need a sort of a reverse CATransform3d
- In iOS is it possible to change a View's coordinate system so that 0,0 is top right corner?
- How to create complex animation with better performance in iOS?
- Why do my images not display in my panels?
- Cannot repaint new elements without repainting old ones
- Dynamic Text Boxes disappearing in AS3
- Resize a UITableView
- JToggleButton - how to get selected state?
- Java Swing - GUI not refreshing or freeze after java 1.8 updates
- Check if current page is frame with javascript
- Subsetting a data frame for all the unique values of a row
- Websocket messages after handshake
Related Questions in EVENLY
- Distribute evenly in 2D
- Distribute dataset evenly by range of id in PySpark
- Evenly redirect users to 18 different pages AND confirm submission
- Distribute a group of buttons evenly inside an Android Layout
- UIView resize evenly
- Sample Elements with Evenly Distributed Value
- php split array into smaller even arrays
- Distribute matches 'tournament friendly'
- How to get an evenly distributed sample from Perl array values?
- Equal sized cells in NSSegmentedControl
- Evenly distribute repetitive strings
- distribute types of item in an array as evenly as possible
- How can I make all Buttons the same height and width when one of them is facebook LoginButton
- Coordinates of equally distanced n points on a circle in R?
- Evenly distribute arrays data between processes in MPI
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
When you change the width and height of the frame, also change the x and y position of the frame by half those amounts.
For example, if your frame is currently (40, 60, 100, 200) and you want it to be wider by 20 and higher by 30, make it (30, 45, 120, 230).