setBackButtonBackgroundImage Weard Behaviour on iOS5.1 - ios6

I have two différent behaviour on ios5.1 and ios6.0 with
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:offBackButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
On iOS 6.0
On iOS 5.1 ???
Is there something I'm not doing well ?

You need to specify a stretchable UIImage with UIEdgeInsets as below:
UIImage *normalStateImage = [[UIImage imageNamed:#"image"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)];
UIImage *pressedStateImage = [[UIImage imageNamed:#"image-pressed"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:normalStateImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:pressedStateImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
iOS 6.x is clever enough to determine the image sizes and stretch according to it.

Related

Windows update KB4040972/73 causes black images with WPF classes

I have an application relying on Deep zoom images (convertion from a PNG to a pyramid of JPGs in various scale) which we use DeepZoomTools.dll for. This is relying on PresentationCore.dll and has been working fine for years.
After the rollout of KB4040972 and KB4040973, the conversion from PNG to JPG generates (depending on coordinates) black images instead of the image it should contain.
If the below code is run in a console or desktop app, it works.
It ONLY doesn't work if run under high privilege SYSTEM account (e.g. from Task scheduler).
I have created a project to reproduce the issue, code below:
public static void TestConvert2(string strFileName, string strOutFileName) {
JpegBitmapEncoder jpegBitmapEncoder = new JpegBitmapEncoder();
jpegBitmapEncoder.QualityLevel = 1 + (int) Math.Round(0.95 * 99.0);
BitmapEncoder encoder = jpegBitmapEncoder;
Int32Rect inputRect = new Int32Rect(0, 0, 255, 255);
Rect outputRect = new Rect(0, 0, 255, 255);
Uri bitmapUri = new Uri(strFileName, UriKind.RelativeOrAbsolute);
BitmapDecoder bitmapDecoder = BitmapDecoder.Create(bitmapUri,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
bitmapDecoder = BitmapDecoder.Create(bitmapUri, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.None);
BitmapSource inputFrame = (BitmapSource) bitmapDecoder.Frames[0];
BitmapSource source1 = (BitmapSource) new CroppedBitmap(inputFrame, inputRect);
DrawingVisual drawingVisual = new DrawingVisual();
using(DrawingContext drawingContext = drawingVisual.RenderOpen()) {
drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)), null, outputRect);
drawingContext.DrawImage((ImageSource) source1, outputRect);
drawingContext.Close();
}
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(255, 255, 96.0, 96.0, PixelFormats.Default);
renderTargetBitmap.Render((Visual) drawingVisual);
source1 = (BitmapSource) new FormatConvertedBitmap((BitmapSource) renderTargetBitmap, PixelFormats.Bgr24, (BitmapPalette) null, 0.0);
BitmapFrame frameToCache = BitmapFrame.Create(source1, (BitmapSource) null, null, (ReadOnlyCollection < ColorContext > ) null);
encoder.Frames.Add(frameToCache);
using(FileStream fileStream = new FileStream(strOutFileName, FileMode.Create)) {
encoder.Save((Stream) fileStream);
fileStream.Flush();
}
}
Any clues out there?
Microsoft has published an article where they state that they are aware of this problem and are working on a resolution. They also provide a workaround, basically to temporary remove the September 12, 2017, Security and Quality Rollup update.
See: https://support.microsoft.com/en-us/help/4043601/rendering-issues-after-the-september-12-2017-net-security-and-quality
Discussion continued on https://social.msdn.microsoft.com/Forums/vstudio/en-US/0f14f14c-5cd3-4505-9168-2ef9dc1f7031/kb-4041083-kb-4040973-has-broken-wpf-rendering-in-services?forum=wpf
Seems to be more than me having this issue.
For us in the end the recommended update from Microsoft KB4043767 solved this issue. This will be part of the October rollout (currently in Preview).

Menu Button in Cocos2d

Im trying to make the play button on the main menu of my game in Cocos2d which is an image file. I set up the sprite as playButton with the image Play Button.png. When I ran the app it gave me an error that the "itemFromNormalSprite:selectedSprite:target:selector." is deprecated. Anybody have a solution to this problem? Here is my code:
CCMenuItem *playGameButton = [CCMenuItemSprite itemFromNormalSprite:playButton selectedSprite:playButton target:self selector:#selector(buttonTapped:)];
CCMenu *menu = [CCMenu menuWithItems:playGameButton, nil];
menu.position = ccp(size.width/2, size.height/1.5);
[self addChild:menu z:5];
CCMenuItem *playGameButton = [CCMenuItemImage itemFromNormalImage:playButton selectedImage:playButton disabledImage:disabledPlayButton target:self selector:#selector(buttonTapped:)];
CCMenu *menu = [CCMenu menuWithItems:playGameButton, nil];
menu.position = ccp(size.width/2, size.height/1.5);
[self addChild:menu z:5];

custom right bar button item in ios6 is not transparent

i am creating a custom right bar button item for my navbar using the following code :
// create a toolbar
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 50, 44.01)];
// create the array to hold the button, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:1];
// create a toolbar item with image
NSString* pathToSettingsResourceFile = [[NSBundle mainBundle] pathForResource:#"19-gear" ofType:#"png"];
UIImage* settingsImage = [[[UIImage alloc] initWithContentsOfFile:pathToSettingsResourceFile] autorelease];
settings = [[UIBarButtonItem alloc]initWithImage:settingsImage style:UIBarButtonItemStylePlain target:self action:#selector(showSettings:)];
settings.enabled = FALSE;
// add button to toolbar
[buttons addObject:settings];
[tools setItems:buttons animated:NO];
[buttons release];
// add toolbar as a right bar button item
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:tools] autorelease];
[tools release];
until ios 6 this works as expected, from ios 6 i am getting this weird rectangle background
and adding
tools.opaque = NO;
tools.backgroundColor = [UIColor clearColor];
doesn't help,
please help me get rid of this background
Thanks in advance,
Amit
I know this is an old thread, but I had the same issue, and thought you might be interested in what I discovered.
A work-around is available in this thread (the answer by jd, not the "accepted" answer).
You should be able to get the behavior you want with this code:
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];
[tools setBackgroundImage:maskedImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
Although this works, I am not convinced that it is the correct way to do it, so I started a new thread here in case anyone knows the secret code for making a UIToolbar containing rectangle behave as a transparent object should.

F# WPF - displaying a simple object in Viewport3D

I'm trying to get into generating 3D graphics in F# (as was apparent from my previous question) with very little time and very little initial knowledge of F#. I'm studying Tomas Petricek's fractal example, but I can't really make heads or tails of it. I've managed to define a window with a Viewport3D object in XAML, initialize and display it from F#. But as far as creating 3d objects in F# and displaying them goes, I'm lost in a sea of fractal generation, coordinate translation, and other calculations.
Could somebody provide a simple example, of creating one really simple object in F# (a single cube, or just a triangle) and display it in the WPF window? That would be huge help.
Thank you.
Here's a simple example with two triangles making a single square:
#if INTERACTIVE
#r "PresentationCore"
#r "PresentationFramework"
#r "WindowsBase"
#r "System.Xaml"
#endif
open System.Windows
open System.Windows.Controls
open System.Windows.Media
open System.Windows.Media.Media3D
let grp = Model3DGroup()
let geo = MeshGeometry3D()
// Point collection
for x,y,z in [0.5, 0.0, 0.0;
1.0, 0.0, 0.0;
0.5, 0.5, 0.0;
1.0, 0.5, 0.0] do
geo.Positions.Add(Point3D(x,y,z))
// First triangle
for i in [0;1;2] do geo.TriangleIndices.Add(i)
// Second triangle - order matters for deciding front vs. back
for i in [2;1;3] do geo.TriangleIndices.Add(i)
// Create a model with the mesh and a front and back material
let model =
GeometryModel3D(
Geometry = geo,
Material = DiffuseMaterial(Brushes.Black),
BackMaterial = DiffuseMaterial(Brushes.Red))
grp.Children.Add(model)
// add light so back color is visible
grp.Children.Add(AmbientLight())
// set up a continuous rotation around the y-axis
let rotation = AxisAngleRotation3D(Axis = Vector3D(0.,1.,0.))
let anim =
Animation.DoubleAnimation(0.0, 360., Duration(System.TimeSpan.FromSeconds 2.),
RepeatBehavior = Animation.RepeatBehavior.Forever)
rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, anim)
// apply the rotation to the geometry
grp.Transform <- RotateTransform3D(rotation)
// create a camera pointing at the triangle
let cam = PerspectiveCamera(Point3D(0.,0.,2.), Vector3D(0., 0., -1.), Vector3D(0., 1., 0.), 60.)
// set the viewport up with the camera and geometry
let vprt = Viewport3D(Camera = cam)
vprt.Children.Add(ModelVisual3D(Content = grp))
// add the viewport to a window
let wnd = Window(Content = vprt, Title = "3D", Visibility = Visibility.Visible)

Wavy underlines as a TextDecoration: what I am doing wrong?

I want to create wavy underlines using TextDecoration (in a control similar to RichTextBox).
I did the following thing:
private static Pen CreateErrorPen() {
var geometry = new StreamGeometry();
using (var context = geometry.Open()) {
context.BeginFigure(new Point(0.0, 0.0), false, false);
context.PolyLineTo(new[] {
new Point(0.75, 0.75),
new Point(1.5, 0.0),
new Point(2.25, 0.75),
new Point(3.0, 0.0)
}, true, true);
}
var brushPattern = new GeometryDrawing {
Pen = new Pen(Brushes.Red, 0.2),
Geometry = geometry
};
var brush = new DrawingBrush(brushPattern) {
TileMode = TileMode.Tile,
Viewport = new Rect(0.0, 1.5, 9.0, 3.0),
ViewportUnits = BrushMappingMode.Absolute
};
var pen = new Pen(brush, 3.0);
pen.Freeze();
return pen;
}
This almost works, but depending on the underlined word position in text, underlines often show up as a pattern of several superimposed waves. Also the underlines are a bit blurry even when they are correct (wpf problem with drawing between pixels, I suppose).
My solution was kind of a trial-and-error, so I might have gone a wrong way, especially with Viewport/ViewportUnits.
What am I doing wrong and is there a way to get crisp underlines?
Thanks in advance.
bstoney had a solution to this problem here. The key seems to be setting the Viewbox as well as the Viewport such that the waves are seperated vertically, so you only get 1 in the underline.
There are some breaks in the wave that can be eliminated by extending it to the right and changing the Viewbox from so it starts from X=1 instead of 0:
<VisualBrush x:Key="WavyBrush" TileMode="Tile" Viewbox="1,0,3,3" ViewboxUnits="Absolute" Viewport="0,-1,6,4" ViewportUnits="Absolute">
<VisualBrush.Visual>
<Path Data="M 0,1 C 1,0 2,2 3,1 4,0 5,2 6,1" Stroke="Red" StrokeThickness="0.2"/>
</VisualBrush.Visual>
</VisualBrush>

Resources