I manually added UITabbarController in storyboard which is not root view controller. I added tabbar items to it and set segue relationships. I also set image and title of each tabbar item in code when the first view controller of UITabbarController is about to be presented but no matter what I do only the first item's image is visible. Other items images become visible only when they are tapped and their views are actually loaded. Any inputs how to fix it ?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if ([segue.identifier isEqualToString:#"AfterLogin"]) {
UITabBarController *tabBarController = [segue destinationViewController];
NSArray *tabBarItems = tabBarController.tabBar.items;
UITabBarItem *item1 = tabBarItems[0];
UITabBarItem *item2 = tabBarItems[1];
UITabBarItem *item3 = tabBarItems[2];
UITabBarItem *item4 = tabBarItems[3];
[item1 setImage:[[UIImage imageNamed:#"image1_static"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item1 setSelectedImage:[[UIImage imageNamed:#"image1_active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
item1 = #"";
item1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
[item2 setImage:[[UIImage imageNamed:#"image2_static"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item2 setSelectedImage:[[UIImage imageNamed:#"image1_active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
item2.title = #"";
item2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
[item3 setImage:[[UIImage imageNamed:#"image3_static"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item3 setSelectedImage:[[UIImage imageNamed:#"image3_active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
item3.title = #"";
item3.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
[item4 setImage:[[UIImage imageNamed:#"image4_static"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item4 setSelectedImage:[[UIImage imageNamed:#"image4_active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
item4.title = #"";
item4.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
}
}
Related
I am trying to fit tool bar from QDockWidget and view from QGraphicsView in a same window.
But it is not getting fit properly. I am expecting view window should start from below the tool bar icons. And view should occupy the whole window.
QWidget* p = new QWidget();
QBoxLayout* toolLayout = new QBoxLayout(QBoxLayout::LeftToRight,p);
toolLayout->setContentsMargins(0, 0, 0, 0);
auto toolbar = new QToolBar;
toolbar->setIconSize(QSize(45,45));
toolLayout->addWidget(toolbar,0,Qt::AlignTop);
const QIcon newIcon = QIcon::fromTheme("document-new", QIcon(":/img/c.png"));
QAction* zoomIn = new QAction(newIcon, tr("&Zoom In"), this);
const QIcon newIcon1 = QIcon::fromTheme("document-new", QIcon(":/img/c1.png"));
QAction* zoomOut = new QAction(newIcon1, tr("&Zoom Out"), this);
const QIcon newIcon2 = QIcon::fromTheme("document-new", QIcon(":/img/c2.png"));
QAction* fitIn = new QAction(newIcon2, tr("&Fit In"), this);
toolbar->addAction(zoomIn);
toolbar->addAction(zoomOut);
toolbar->addAction(fitIn);
QObject::connect(zoomIn, SIGNAL(triggered()), this, SLOT(zoomIn()));
scene = new QGraphicsScene(this);
view = new QGraphicsView(this);
view->setScene(scene);
toolLayout->addWidget(view);
p->setLayout(toolLayout);
QLabel *label = new QLabel("myView");
label->setStyleSheet(
"QLabel { padding-left: 5px;font-size: 5px;"
}");
setWidget(p);
Where am I wrong ?
When I create multiple radio buttons through a for loop and using the function addTarget, how can I handle multiple radio buttons using addTarget by tag or sender in swift 3.0?
Here is the solution change it according to your requirement
(SWIFT 4)
// create button array to save all button
var buttonArray = [UIButton]()
func createButtons(){
//create 5 buttons
for i in 1...5 {
let button = UIButton(frame: CGRect(x: 0, y: i*55, width: 130, height: 50))
//set same background for each button
button.backgroundColor = UIColor.darkGray
// set different ittle for button
button.setTitle("Button No \(i)", for: .normal)
// set different tag to differentiate betwwen button
button.tag = i
// set same target for each button
button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside)
buttonArray.append(button)
//add all buttons to main view
view.addSubview(button)
}
// we make first button of different color so that it can act as radio button
let firstBtn = buttonArray[0]
firstBtn.backgroundColor = UIColor.green
}
#objc func buttonTapped(_ tappedBtn : UIButton){
// here we get tapped button so from array of button we match the selected one using tag and make it of different color all all other buttons of some different color
for button in buttonArray {
if(button.tag == tappedBtn.tag){
button.backgroundColor = UIColor.green
}else{
button.backgroundColor = UIColor.darkGray
}
}
}
Scenario: Create and display an overlay (ancillary) UIWindow.
Related Discussion: How do I toggle between UIWindows?
Code:
fileprivate func displayOverLay() {
let myWindow = {() -> UIWindow in
let cWindow = UIWindow(frame: CGRect(x: 10, y: 200, width: 300, height: 300))
cWindow.backgroundColor = UIColor.gray.withAlphaComponent(0.5)
cWindow.tag = 100
return cWindow
}()
myWindow.makeKeyAndVisible()
myWindow.windowLevel = UIWindowLevelAlert
let storyboard = UIStoryboard(name: "Hamburger", bundle: nil)
let vc = storyboard.instantiateInitialViewController()
myWindow.rootViewController = vc
return
}
Here's the shared UIApplication window status:
(lldb) po UIApplication.shared.windows
▿ 2 elements
- 0 : <UIWindow: 0x7fcffc804860; frame = (0 0; 375 667); autoresize = W+H; gestureRecognizers = <NSArray: 0x600000051280>; layer = <UIWindowLayer: 0x60000003e840>>
- 1 : <UIWindow: 0x7fcff9407240; frame = (10 200; 300 300); tag = 100; gestureRecognizers = <NSArray: 0x608000052810>; layer = <UIWindowLayer: 0x608000220420>>
(lldb) po UIApplication.shared.keyWindow!
<UIWindow: 0x7fcff9407240; frame = (10 200; 300 300); tag = 100; gestureRecognizers = <NSArray: 0x608000052810>; layer = <UIWindowLayer: 0x608000220420>>
Here's the result: no gray window sceen
Important Note: If I brake at the end of the displayOverLay() and do a 'po myWindow', and then continue, I do get the display.
So it appears that I'm missing some sort of event to have the UIWindow appear.
What is needed to force the new UIWindow w/contents to actually display?
You need to keep a reference to the created window, otherwise ARC will take care of disposing the window after you return from your function.
You could for instance return the newly created window from your function and store it in a property of the class from which your are calling the function.
Refrence : https://stackoverflow.com/a/26578895/6619234
how to erase and redraw circle on click evnet?
i tried to call addCircleView method on click event but circle is overlapping every time.
class CircleClosing: UIView {
var circleLayer: CAShapeLayer!
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = UIColor.clear
// Use UIBezierPath as an easy way to create the CGPath for the layer.
// The path should be the entire circle.
let circlePath : UIBezierPath!
circlePath = UIBezierPath(arcCenter: CGPoint(x: frame.size.width / 2.0, y: frame.size.height / 2.0), radius: (frame.size.width - 5)/2, startAngle: 0.0, endAngle: CGFloat(M_PI * 2.0), clockwise: true)
// Setup the CAShapeLayer with the path, colors, and line width
circleLayer = CAShapeLayer()
circleLayer.path = circlePath.cgPath
circleLayer.fillColor = UIColor.clear.cgColor
circleLayer.strokeColor = UIColor.blue.cgColor
circleLayer.lineWidth = 20.0;
// Don't draw the circle initially
circleLayer.strokeEnd = 0.0
// Add the circleLayer to the view's layer's sublayers
}
override func layoutSubviews()
{
let frame = self.layer.bounds
circleLayer.frame = frame
layer.addSublayer(circleLayer)
}
required init?(coder aDecoder: NSCoder)
{ super.init(coder: aDecoder) }
func animateCircle(duration: TimeInterval) {
// We want to animate the strokeEnd property of the circleLayer
let animation = CABasicAnimation(keyPath: "strokeEnd")
// Set the animation duration appropriately
animation.duration = duration
// Animate from 0 (no circle) to 1 (full circle)
animation.fromValue = 0
animation.toValue = 1
// Do a linear animation (i.e. the speed of the animation stays the same)
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
// Set the circleLayer's strokeEnd property to 1.0 now so that it's the
// right value when the animation ends.
circleLayer.strokeEnd = 1.0
// Do the actual animation
circleLayer.add(animation, forKey: "animateCircle")
}
}
Add in your subview
func addCircleView() {
var circleView : CircleClosing!
let diceRoll = CGFloat(510) //CGFloat(Int(arc4random_uniform(7))*50)
let diceRolly = CGFloat(70)
let circleWidth = CGFloat(40)
let circleHeight = circleWidth
// Create a new CircleView
circleView = CircleClosing(frame:CGRect(x:diceRoll,y: diceRolly,width: circleWidth,height: circleHeight) )
view.addSubview(circleView)
// Animate the drawing of the circle over the course of 1 second
circleView.animateCircle(duration: 20.0)
}
Thanks in Advance
var circleView : CircleClosing!
func addCircleView() {
let diceRoll = CGFloat(510) //CGFloat(Int(arc4random_uniform(7))*50)
let diceRolly = CGFloat(70)
let circleWidth = CGFloat(40)
let circleHeight = circleWidth
//Add this line here to remove from superview
circleView.removeFromSuperview()
circleView = CircleClosing(frame:CGRect(x:diceRoll,y: diceRolly,width: circleWidth,height: circleHeight) )
view.addSubview(circleView)
// Animate the drawing of the circle over the course of 1 second
circleView.animateCircle(duration: 20.0)
}
I am new to famo.us like everybody else.
I cannot think of a way to increase the height of each item (probably surface) inside my scrollview on clicking that item.
Eg. like below list view below
item 1
item 2
item 3
Now Clicked item 2
item 1
item 2
details of item 2
item 3
Here is a way I was able to achieve clicking to adjust height. It gets a bit more complicated is you want to animate the size.
Here is the simple click example..
Hope it helps!
var Engine = require('famous/core/Engine');
var Surface = require('famous/core/Surface');
var Scrollview = require('famous/views/Scrollview');
var surfaces = [];
var scrollview = new Scrollview();
scrollview.sequenceFrom(surfaces);
for (var i = 0; i < 5; i++) {
var surface = new Surface({
size:[undefined,200],
properties: {
backgroundColor:'hsl('+(i*360/8)+',100%,50%)'
}
});
surface.open = false;
surface.on('click',function(){
var size = this.open ? [undefined,200] : [undefined,400] ;
this.setSize(size);
this.open = !this.open;
}.bind(surface));
surfaces.push(surface);
surface.pipe(scrollview);
};
context.add(scrollview);