I am currently using MPVolume to stream audio from my app to Apple TV.
MPVolume has route button and I want to expand the touching area of this.
UIButton *button;
for (id object in self.volumeView.subviews) {
if ([object isKindOfClass:[UIButton class]]) {
button = object;
}
}
I use snippet code above to catch up this button and set the new frame for it but it does not work.
You can subclass MPVolumeView, override layoutSubviews method, on this method, find the Button and resize it.
- (void)layoutSubviews {
[super layoutSubviews];
for (UIView *view in self.subviews) {
if (view.class == NSClassFromString(#"MPButton")){
//Do something here
}
}
}
Related
I want to implement a function whereby a lock button is pressed which locks the current state of my app and prevents all scrolling and button pressing until the unlock button is pressed. I have no idea how to go about this please give me ideas and sample code! There is a similar function in the app GoodReader if anyone knows of this.
Thanks!
try something like:
for(UIView* subview in [self.view subviews])
if(subview != yourLockButton)
subview.userInteractionEnabled = NO;
Disable all the scroll in the view
- (void)disableScrollView
{
for (UIScrollView *view in your_viewController.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
view.scrollEnabled = NO;
}
}
}
I'm trying to bringtofront my subview because the delete button keeps disappearing.
#implementation MyCell : UITableViewCell
- (void)layoutSubviews
{
[super layoutSubviews];
for (UIView *subview in self.subviews) {
for (UIView *subview2 in subview.subviews) {
NSLog(#"HERE!");
if ([NSStringFromClass([subview2 class]) isEqualToString:#"UITableViewCellDeleteConfirmationView"]) {
NSLog(#"got inside the if!");
[subview2 sendSubviewToBack:subview];
[subview bringSubviewToFront:subview2];
[self.superview bringSubviewToFront:subview2];
}
}
}
}
#end
I subclassed UITableViewCell. Both the NSLogs are printing so I know it's getting in there, but I've tried all 3 of these methods to put the view in front. Any ideas why this wouldn't be working?
subview2 is a subview of subview, which is a subview of self. The receiver of the sendSubviewToBack: or bringSubviewToFront: message must be the superview of the view given as argument. Therefore only the second one of the calls you make is valid. The correct calls would be
[self.superview bringSubviewToFront:self];
[self bringSubviewToFront:subview];
[subview bringSubviewToFront:subview2];
(And the same for sendSubviewToBack:.)
As for your actual problem, I can't figure out the view hierarchy you are using from the code posted, but it seems that it is incorrect. You should probably not have your custom views as direct subviews of self, but rather as subviews of self.contentView (as per Apple's documentation).
Problem: Using NIAttributedLabel in UITableViewCell with Action(tap, navigate)
adding a link in label
adding label to cell
adding cell to model with action tap
Here is the problem, if I touch the label on the link, it actually does not show the link but act the tap action.
But if I add a UIButton in UITableViewCell in the same way, the action does not happen and the button response when I touch on the button.
So I guess it is the problem with the label.
How can I solve it?
I figured out this finally;
adding function to file NIAttributedLabel.m
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
// never return self. always return the result of [super hitTest..].
// this takes userInteraction state, enabled, alpha values etc. into account
UIView *hitResult = [super hitTest:point withEvent:event];
// don't check for links if the event was handled by one of the subviews
if (hitResult != self) {
return hitResult;
}
if (self.explicitLinkLocations || self.detectedlinkLocations) {
BOOL didHitLink = ([self linkAtPoint:point] != nil);
if (!didHitLink) {
// not catch the touch if it didn't hit a link
return nil;
}
}
return hitResult;
}
remove all [super touch XXXX] functions in all touchXXX;
then, it works!
In my app I need to call some UIViews more than once. But in one of my method, i've a code like :
[self addSubview:UIImageView];
But i've read that addsubview method must be call once. So, to let the code how is it, how could I check if it's already on subview ? Like :
if ([UIImageView isOnSubview] == NO)
{
[self addSubview:UIImageView];
}
Because I don't find any method to check this :/
Thank you !
You are probably looking for UIView's -(BOOL)isDescendantOfView:(UIView *)view; taken in UIView class reference.
use this one
for (UIView *subview in [self subviews])
{
NSLog(#"%#", subview);
// ---------- remember one thing there should be one imageview ------
if(![subview isKindOfClass:[UIImageView class]])
{
[self addSubview:UIImageView];
}
}
I have custom UIToolbar's that sit ontop of my keyboard when it displays and that I use to insert pre-formatted text. My problem is that I have one UITextView and two UITextField's that are potential users of my pre-formatted text.
When the buttons call an IBAction, how can I tell which element has focus and is the firstResponder?
Attempt #2 at asking my question smartly:
I need to call [textElement selectedRange]; on the UITextField or UITextView that has focus. How can I declare textElement in a way that it doesn't matter which of the view UIText* classes it is?
If I do the following...
UIView *textElement = [self my_method_of_getting_first_responder];
NSRange range = [textElement selectedRange];
I of course get the
UIView does not declare selector 'selectedRange'
Thanks!
If I understood question, you want to click some button, and then get the link to you currently active text field? Then you have to go with category on UIView:
#implementation UIView (FindFirstResponder)
- (BOOL)findFirstResponder
{
if (self.isFirstResponder) {
return YES;
}
for (UIView *subView in self.subviews) {
if ([subView findFirstResponder]) {
return YES;
}
}
return NO;
}
#end
You can call this category method on UIWindow from you view controller. To get window use UIWindow *window= self.view.window;