[Solved] Can’t see the button

Simple remove self.myView.hidden = YES; To add you click listener, two solution: By code in your viewDidLoad: – (void)viewDidLoad { [super viewDidLoad]; [mybutton addTarget:self action:@selector(myButtonClick:) forControlEvents:(UIControlEvents)UIControlEventTouchDown]; } – (void)myButtonClick:(id)sender { myButton.hidden = YES; } Or via interface Builder (preferred), The easiest way is to actually define the handler/action in Xcode using the IBAction declaration in … Read more

[Solved] Present a viewcontroller in UIView [closed]

To add a view controller to another view controller, you can do the following: Inside the parent view controller class: addChildViewController(someViewController) view.addSubview(someViewController.view) someViewController.didMove(toParentViewController: self) someViewController.view.translatesAutoresizingMaskIntoConstraints = false Then, set the layout constraints to position the view controller: NSLayoutConstraint.activate([ someViewController.view.leadingAnchor .constraint(equalTo: view.leadingAnchor ), someViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), someViewController.view.bottomAnchor .constraint(equalTo: view.bottomAnchor ), someViewController.view.topAnchor .constraint(equalTo: view.topAnchor ) ]) view.layoutIfNeeded() 2 … Read more

[Solved] How to make Custom UIview which have rounded cornes, in iphone? [closed]

For this you need to import Quartz framework. You can also set Bordercolor, shadow color, corner width, etc to that view. #import <QuartzCore/QuartzCore.h> And try this code. [self.YourView.layer setCornerRadius:1.0]; [self.YourView.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]]; [self.YourView.layer setBorderWidth:1.0]; [self.YourView.layer setShadowColor:[UIColor lightGrayColor].CGColor]; 2 solved How to make Custom UIview which have rounded cornes, in iphone? [closed]

[Solved] Creating a subclass of UIView [closed]

Declare your method in your Interface @interface AVView : UIView – (UIView *) buildBestView; @end Use that in the other class AVView *avView = [[AVView alloc] initWithFrame:CGRectMake:(0,0, 100, 100)]; [avView buildBestView]; 3 solved Creating a subclass of UIView [closed]

[Solved] iOS how present Modal ViewController from Uiview

When you need a communication between UIView instance and UIViewController, there are a few known iOS concepts, which you should adhere to. As you have figured out that UIView cannot really present a new controller (missing either presetViewController:animated:completion methods or navigationController property, which are both present in UIViewController). Views are supposed to be the most … Read more

[Solved] How to push or present UIViewcontroller or storyboard from UIView subclass?

You need to implement protocol method for custom UIView class. For example; #import <UIKit/UIKit.h> @protocol YourCustomViewDelegate <NSObject> – (void)buttonTapped; @end @interface YourCustomView : UIView @property (nonatomic, strong) id< YourCustomViewDelegate > delegate; @end And the .m file you can call buttonTapped delegate method. – (void)myCustomClassButtonTapped:(id)sender { [self.delegate buttonTapped]; } For proper work; set your custom view … Read more

[Solved] How can I resize the UIImage to specific size

Here’s how you can resize the image while preserving its aspect ratio. The code below is from a category for UIImage: + (UIImage*)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize { float heightToWidthRatio = image.size.height / image.size.width; float scaleFactor = 1; if(heightToWidthRatio > 0) { scaleFactor = newSize.height / image.size.height; } else { scaleFactor = newSize.width / image.size.width; } CGSize … Read more

[Solved] What’s the analogue of the display method for UIView?

Apple’s documentation is a rather rich source of information – most of the time. The UIViewclass reference notes a method that informs the system that a view needs to be redrawn: setNeedDisplay Something you should have been aware by browsing the documentation for a couple of seconds. solved What’s the analogue of the display method … Read more

[Solved] How to use autoresize on 2 UIViewControllers? [closed]

Well, part of the problem is that this is illegal: [UIViewControllers1.view addSubview:UIViewControllers2.view]; You must never just wantonly add one view controller’s view to another view controller’s view. There is only one way in which that is allowed outside of a built-in parent-child structure that does it for you (UINavigationController, UITabBafController, UIPageViewController), and that is when … Read more

[Solved] How to draw a circle and move it / drag it on touch in IOS? [closed]

Well you could create a custom UIView and overwrite it’s drawRect method to draw the circle. The drawRect method would then look like this: – (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(ctx, [[UIColor redColor] CGColor]); CGContextFillEllipseInRect(ctx, self.bounds); } Don’t forget to set the views background color to the clear color. To handle the movement, add … Read more