I try this code for set the alpha value in button image:
UIImageView *imageTopView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:#"Top_80.png"]];
imageTopView.alpha = 0.5;
topBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[topBtn addTarget:self action:#selector(btnRotatingObj:)
forControlEvents:UIControlEventTouchUpInside];
[topBtn setImage: imageTopView.image forState:UIControlStateNormal];
[topBtn setTitle:#"TOP" forState:UIControlStateNormal];
[self.view addSubview:topBtn];
its not working.....
You are setting the image of the button with the image of your image view. Your image view has an alpha of 0.5, but of course not your image.
Instead, add the image view as a subview of your button:
[topBtn addSubView:imageTopView];
Related
My app has a ARSCNView and recognises an image with image detection
The goal is to look for an image and once it is recognised change the world position to its center
Something is not working. Any help would be greatly appreciated!
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard let imageAnchor = anchor as? ARImageAnchor else {return}
if let imageName = imageAnchor.referenceImage.name {
switch imageName {
case "myImage":
//OK, the image gets recognized
let refSphere = SCNSphere(radius: 0.02)
let refNode = SCNNode(geometry: refSphere)
refSphere.firstMaterial?.diffuse.contents = UIColor.red.withAlphaComponent(0.8)
node.addChildNode(refNode) // OK, there's a sphere representation on top of the recognized image
sceneView.session.pause()
self.sceneView.session.setWorldOrigin(relativeTransform: node.simdTransform) // Trying to move the world Origin to the center of recognized image
sceneView.session.run(configuration, options: [.resetTracking])
let box = SCNBox(width: 0.05, height: 0.05, length: 0.05, chamferRadius: 0.01)
let boxNode = SCNNode(geometry: box)
box.firstMaterial?.diffuse.contents = UIColor.green.withAlphaComponent(0.9)
boxNode.position = SCNVector3(0,0,0)
sceneView.scene.rootNode.addChildNode(boxNode) // Not OK - I was expecting to have world Origin in the center of the recognized image and a green box on top of it
default:
print("other")
}
}
}
I did it this way:
self.sceneView.session.setWorldOrigin(relativeTransform: imageAnchor.transform)
Don't know if it's still relevant to you, but after you change the world origin, with self.sceneView.session.setWorldOrigin, you resume session with .resetTracking option, which sets your world origin to the location of the camera.
Getting rid of that option should help.
I just updated to Xcode 9 and run to an iOS11 simulator. My custom view for the navaagation bar title is shifted down.
This code was working before i updated; it was vertically centered before
companyCountryView = CompanyNameView(frame: CGRect(x: 0, y: 0, width: Utils.getScreenWidth() - 150, height: 35))
companyCountryView.companyLbl.text = ""
companyCountryView.countryLbl.text = ""
self.navigationItem.titleView = companyCountryView
Even though I change values for y and height, no effect at all.
It seems the width value i used does not do any effect too.
I have solved it! You need to override the intrinsicContentSize in your custom view class and put the size of the view there:
class CustomView: UIView {
override var intrinsicContentSize: CGSize {
return CGSize(width: Utils.getScreenWidth() - 150.0, height: 35.0)
}
}
So in my application i have chat and i added CartesianGridLineAnnotation:
RadCartesianChart chart;
CartesianGridLineAnnotation cartesianGridLineAnnotation;
cartesianGridLineAnnotation = new CartesianGridLineAnnotation
{
Foreground = Brushes.White,
Background = Brushes.Green,
Axis = chart.VerticalAxis,
Stroke = Brushes.Red,
StrokeThickness = 1,
};
chart.Annotations.Add(...);
So as you can see i try to set Background color but the problem is that i cannot see any change in my CartesianGridLineAnnotation Label.
Other properties when changed look as expected.
Update
This is how i am populate my label:
cartesianGridLineAnnotation.Label = "bla bla";
As you can see i cannot see the backgroud color.
I integrate the iCarousel into my application.It is working fine.But my requirement is to display the two buttons in single view and specific actions for these two buttons.I display the buttons as
- (UIView *) carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{
UIView *sampleView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 250, 300)];
sampleView.backgroundColor=[UIColor whiteColor];
UIButton* btntrans=[UIButton buttonWithType:UIButtonTypeCustom];
[btntrans setFrame:CGRectMake(45, 40, 105, 50)];
[btntrans setBackgroundColor:[UIColor clearColor]];
btntrans.titleLabel.font = [UIFont fontWithName:#"Arial-BoldMT" size:15];
[btntrans setTitle:#"" forState:UIControlStateNormal];
[btntrans setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[sampleView addSubview:btntrans];
UIButton* btntrans1=[UIButton buttonWithType:UIButtonTypeCustom];
[btntrans1 setFrame:CGRectMake(45, 90, 105, 50)];
[btntrans1 setBackgroundColor:[UIColor clearColor]];
btntrans1.titleLabel.font = [UIFont fontWithName:#"Arial-BoldMT" size:15];
[btntrans1 setTitle:#"" forState:UIControlStateNormal];
[btntrans1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[sampleView addSubview:btntrans1];
return sampleView;
}
we can use
-(void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index
{
NSLog(#"ITEM SELECTED");
}
for whole view selection.but How to set the two specific actions for these two buttons?
Thanks in advance.
Bind the button action to your view controller when you create the item view, then use indexForViewOrSubview: method of carousel in your action method to work out which button was pressed.
If you are using a nib to create your views, take a look at the controls example included with the iCarousel example projects for how to do this.
Why don't you try this:
[btntrans addTarget:self
action:#selector(first_action)
forControlEvents:UIControlEventTouchUpInside];
Similarly,
[btntrans1 addTarget:self
action:#selector(second_action)
forControlEvents:UIControlEventTouchUpInside];
Correspondingly in the events:
- (void)first_action:(id)sender{
//This will get you the index of the selected view
NSInteger index = [self.carousel indexOfItemViewOrSubview:sender];
.......
//Do whatever you feel like
}
I have the following code:
void Test()
{
currentImage.Source = GetBitmap();
RenderTargetBitmap rtb = new RenderTargetBitmap(100, 100, 96.0, 96.0, PixelFormats.Default);
rtb.Render(currentImage);
}
This code is supposed to render currentImage, which is an Image control in my xaml to a RenderTargetBitmap.
It doesn't work, rtb returns a blank image, the problem is currentImage didn't render itself yet and so this behavior is expected, I think...
To workaround this problem, I wrote this code:
void Test()
{
currentImage.Source = GetBitmap();
this.Dispatcher.BeginInvoke((Action)delegate()
{
RenderTargetBitmap rtb = new RenderTargetBitmap(100, 100, 96.0, 96.0, PixelFormats.Default);
rtb.Render(currentImage);
}, System.Windows.Threading.DispatcherPriority.Render, null);
}
Basically, I wait for currentImage to be rendered and then I can get it properly rendered to my RenderTargetBitmap.
Is there any way to make it work without using this workaround? Force the Image control to render in memory maybe?
thanks!
use a ViewBox to render in memory
Grid grid = new System.Windows.Controls.Grid() { Background = Brushes.Blue, Width = 200, Height = 200 };
Viewbox viewbox = new Viewbox();
viewbox.Child = grid; //control to render
viewbox.Measure(new System.Windows.Size(200, 200));
viewbox.Arrange(new Rect(0, 0, 200, 200));
viewbox.UpdateLayout();
RenderTargetBitmap render = new RenderTargetBitmap(200, 200, 150, 150, PixelFormats.Pbgra32);
render.Render(viewbox);
I think this is a BETTER answer . The viewbox didn't work completely as expected, and it turned out to be an unnecessary overhead.
Here is a copy of that answer (instead of just link)
You need to force a render of the item, or wait for the item to be rendered. You can then use the ActualHeight and ActualWidth properties.
To force a render:
MenuItem item = new MenuItem();
item.Header = "bling";
item.Icon = someIcon;
//Force render
item.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
item.Arrange(new Rect(item.DesiredSize));
In this example the MenuItem has not been given an explicit height or width. However, forcing the render will render it taking the supplied header text and icon into consideration.