Is there a way to protect (to lock) a shape not just from resizing or moving but from deleting too? The shape should be visible, but not movable, resizable or deletable.
I need something like Object ⟶ Lock from InDesign to "lock" the postcard shape on the background.
You can place your shape in a frame, and protect the content of the frame.
Of course, this will only protect the frame (and its content) from accidentally deletion - there is no "password protected" option.
Does this help?
Related
I'm working on a MacOS application that needs to display large images. if I naively set the ImageView to be the full size image, the application's window can be forced to become larger than the screen size. What I'd like to be able to do is work out how large I can make the image while keeping the entire window (which also contains other UI elements) on screen.
I know I can query the amount of available screen space using NSScreen:visibleFrame() but that does not seem to be much help since unless I make a whole load of assumptions about how much space the rest of the UI will take up which then defeats the point of having constraint based UI layout.
The other approach could be to find a way to constrain the window size and then let Cocoa work out the sizes of the views. However, it looks like the UI editors in Xcode only allows static sizes to be specified which is not much help.
It looks like this is possible in SwiftUI (https://www.hackingwithswift.com/quick-start/swiftui/how-to-adjust-the-way-an-image-is-fitted-to-its-space)
Image("example-image")
.resizable()
.aspectRatio(contentMode: .fit)
However, the application I'm working on needs to run on older versions of MacOS than supported by SwiftUI so I need to know how to do this in swift but using plain Cocoa.
The first thing I would try is to modify the priority of the constraints that make the image view large enough to accommodate the image. That would be its content compression resistance priority. I think if you set it to .dragThatCanResizeWindow then you might get the behavior you want for free. That's because the system already constrains a window to the screen size when you drag its edges. So, presumably, that implicit constraint has a higher priority than .dragThatCanResizeWindow.
If that doesn't do it, you can programmatically set a window's maximum frame size by setting its maxSize property. You'll want to set that each time the screen configuration changes or the window moves to a different screen. For the former, you can observe NSApplication.didChangeScreenParametersNotification. For the latter, your window delegate can implement windowDidChangeScreen(_:) or you can observe NSWindow.didChangeScreenNotification.
If I add a basic UIButton all is well, they are always easy to press every time. However, when I make a custom version using my own .png it becomes hard to trigger every time.
My custom button is a little smaller 32x32 and is mostly transparent. Could it simply be that its smaller, could the transparency be a problem..?
many thanks for any thoughts..
Maybe it is because it's smaller than 32x32, try making your transparency layer a little bigger, say 40x40 to have a bigger hit area. I mean use a bigger PNG :)
Check whether you have overhided any touches method and not called super in it...
Keep the frame of the view to 40*40 and clear the background color then set the image which is 32*32... It will work correctly
I have an arrow button that I want to keep small but I want the touch area around it to be bigger.
I used the answer from the post Here but it made my button larger.
The problem is that the picture of the button is larger than the size it is presented in. But I thought there must be a way to do it without editing it or adding a transparent button.
Use a custom button with an image with mode "center"(which means that it doesn't resize with the button size and stays always in the center). Then you can make the button as big as you want and the button image always stays in the middle with the same size.
You should be able to do it by extending the button class and overriding the hitTest method. In your version of this method you can expand the area checked to include a buffer area and return the button if the touch happens within it.
A transparent button behind this button would also work and just point that to the method... I suppose you could go about this multiple ways. One should prefer the option that is simplest with the least overhead.
I have a UITextView that I shrink upon bringing up the keyboard. An issue I just ran into though is as I type past the keyboard, rather than the text start scrolling, the UITextView automatically gets bigger. How can I possibly turn this off?
EDIT
This is not a subclass, this is a plain old UITextView. It's definitely resized and gets visibly bigger (the box around the text extends past the keyboard). Not sure what you mean about flexible width/height. I tried setting it to grow and shrink with the window maybe? But that did nothing for me.
I've tried changing the content size and/or frame size, that didn't help.
I agree something very odd is going on here. Still looking for why it could be resizing.
EDIT
Nevermind. A bad fix I had to force the textview to refresh was being called unexpectedly and causing it to grow.
To my knowledge, a standard UITextView with no special flags applied shouldn't do that. In fact, I don't know that a UITextView does that at all, so my response would be in the form of a question: are you sure that your UITextView is in fact resized to fit completely within the bounds of the visible area above the keyboard? Are you using a plain ol' UITextView and not a subclass? (I know that the TTTextEditor is a class from the Three20 project whose sole purpose is to grow as you type, which is why I'm suspicious about your class doing that by default)
If you want to make sure it doesn't resize, you can try turning off the flexible width and flexible height sections in the measurements tab in IB, and maybe also uncheck "auto-resizes subviews" on the UITextView's parent. Although none of these should be making a difference, turning them off may help diagnose the real problem.
I want to read the string displayed on the screen with finger touch, means as my finger moves over the text displayed on screen, the text below the finger should get highlighted. Is there any way to do this using UITextView or any other class. Also i want to play the sound associated with that word from a sound file which has the sentence already recorded.
If anyone knows it kindly reply.
Thanks in advance.
So that's two questions.
To know where your finger is pointing in the text you need to know where the UITextView has laid out the characters. This is not something the UITextView is documented to support, so next up is drawing text yourself. This stackoverflow question on embedding a custom font has a few links and even some code that will do the trick. What you need to add is keeping track of character advances so you know exactly where each character is rendered (or you could even use other core graphics functions to get exact bounding boxes of each character).
Clearly once you know what character has been tapped you also know the word it is part of. You'll would probably have the best quality if the sentence is recorded both in full and as single words, so that you can play back either when needed. This other stackoverflow question on playing sounds loaded from the internet has a few links and snippets which relate to loading and playing back audio.
I am doing this in an iPhone text editor I am writing. For multiple reasons, I have subclassed a UIView to draw the text (instead of a UITextView) and I had to implement something like this to provide a movable cursor like a text view has. What I did was use a fixed-width font (Courier to be exact), then I took the x-coordinate of the touch and divided it by the width of the character and rounded the answer down. This gives you a character index.
However, if it is possible, find a way to do this without drawing the text yourself (if the text is user entered or really anything other than hardcoded) because Apple provides a lot of functionality in its UITextView class that is a pain to replicate: editing, cursor, word wrap, scrolling, etc.
It might be possible, if you can't get touch events from a subclassed UITextView, to put a transparent view/layer over the top of the text and get touch events from that, then you would only have to figure out a way to turn this on and off for editing.
Kyle
I came up with a handy trick to do this. In drawRect, mimic the text that the UITextView will draw, but don't actually draw the text. Set the font to Helvetica 17-point, and the only semi-tricky part is handling word wrapping. You already have the text to be displayed, and you can get the size of each word in that default font by calling sizeWithFont. Then save the rectangles for each word, and when the user touches the view, find which of the stored rectangles contains the touched point. To test and calibrate the geometry (line spacing, etc), draw the text yourself in a different color. When you get it so that you can only see one of the font colors, you've got it perfect.
I can post my code for this if someone wants it.